static int l_kvsdir_destroy (lua_State *L) { kvsdir_t *d = lua_get_kvsdir (L, -1); if (d) kvsdir_destroy (d); return (0); }
void cmd_watch_dir (flux_t h, int argc, char **argv) { bool ropt = false; char *key; kvsdir_t *dir = NULL; int rc; if (argc > 0 && !strcmp (argv[0], "-r")) { ropt = true; argc--; argv++; } if (argc != 1) msg_exit ("watchdir: specify one directory"); key = argv[0]; rc = kvs_get_dir (h, &dir, "%s", key); while (rc == 0 || (rc < 0 && errno == ENOENT)) { if (rc < 0) { printf ("%s: %s\n", key, strerror (errno)); if (dir) kvsdir_destroy (dir); dir = NULL; } else { dump_kvs_dir (h, ropt, key); printf ("======================\n"); } rc = kvs_watch_once_dir (h, &dir, "%s", key); } err_exit ("%s", key); }
static int load_kvsdir (flux_conf_t cf, kvsdir_t *dir) { kvsitr_t *itr; const char *name; int rc = -1; itr = kvsitr_create (dir); while ((name = kvsitr_next (itr))) { if (kvsdir_isdir (dir, name)) { kvsdir_t *ndir; if (kvsdir_get_dir (dir, &ndir, "%s", name) < 0) goto done; if (load_kvsdir (cf, ndir) < 0) goto done; kvsdir_destroy (ndir); } else { if (load_one (cf, dir, name) < 0) goto done; } } rc = 0; done: kvsitr_destroy (itr); return rc; }
void cmd_dirsize (flux_t h, int argc, char **argv) { kvsdir_t *dir = NULL; if (argc != 1) msg_exit ("dirsize: specify one directory"); if (kvs_get_dir (h, &dir, "%s", argv[0]) < 0) err_exit ("%s", argv[0]); printf ("%d\n", kvsdir_get_size (dir)); kvsdir_destroy (dir); }
static void kz_destroy (kz_t *kz) { if (kz->name) free (kz->name); if (kz->dir) kvsdir_destroy (kz->dir); if (kz->grpname) free (kz->grpname); free (kz); }
static int jobid_exist (flux_t h, int64_t j) { kvsdir_t *d; if (kvs_get_dir (h, &d, "lwj.%ld", j) < 0) { flux_log (h, LOG_DEBUG, "lwj.%ld doesn't exist", j); return -1; } kvsdir_destroy (d); return 0; }
void dirgetas (flux_t *h, const char *dir, const char *key, const char *type) { kvsdir_t *d; if (kvs_get_dir (h, &d, "%s", dir) < 0) log_err_exit ("kvs_get_dir %s", dir); if (type == NULL) { char *value; if (kvsdir_get (d, key, &value) < 0) log_err_exit ("kvsdir_get %s", key); printf ("%s\n", value); free (value); } else if (!strcmp (type, "int")) { int value; if (kvsdir_get_int (d, key, &value) < 0) log_err_exit ("kvsdir_get_int %s", key); printf ("%d\n", value); } else if (!strcmp (type, "int64")) { int64_t value; if (kvsdir_get_int64 (d, key, &value) < 0) log_err_exit ("kvsdir_get_int64 %s", key); printf ("%" PRIi64 "\n", value); } else if (!strcmp (type, "boolean")) { bool value; if (kvsdir_get_boolean (d, key, &value) < 0) log_err_exit ("kvsdir_get_int64 %s", key); printf ("%s\n", value ? "true" : "false"); } else if (!strcmp (type, "double")) { double value; if (kvsdir_get_double (d, key, &value) < 0) log_err_exit ("kvsdir_get_int64 %s", key); printf ("%f\n", value); } else if (!strcmp (type, "string")) { char *s; if (kvsdir_get_string (d, key, &s) < 0) log_err_exit ("kvsdir_get_string %s", key); printf ("%s\n", s); free (s); } else { log_msg_exit ("unknown type (use int/int64/boolean/double/string)"); } kvsdir_destroy (d); }
bool key_exists (flux_t h, const char *key) { char *json_str = NULL; kvsdir_t *dir = NULL; if (kvs_get (h, key, &json_str) == 0) { free (json_str); return true; } if (errno == EISDIR && kvs_get_dir (h, &dir, "%s", key) == 0) { kvsdir_destroy (dir); return true; } return false; }
int kvs_conf_load (flux_t h, flux_conf_t cf) { kvsdir_t *dir = NULL; int rc = -1; flux_conf_clear (cf); if (kvs_get_dir (h, &dir, kvs_conf_root) < 0) goto done; if (load_kvsdir (cf, dir) < 0) goto done; rc = 0; done: if (dir) kvsdir_destroy (dir); return rc; }
static char *getnext_blocking (kz_t *kz) { char *json_str = NULL; while (!(json_str = getnext (kz))) { if (errno != EAGAIN) break; if (kvs_watch_once_dir (kz->h, &kz->dir, "%s", kz->name) < 0) { if (errno != ENOENT) break; if (kz->dir) { kvsdir_destroy (kz->dir); kz->dir = NULL; } } } return json_str; }
static void add_jobinfo (flux_t h, int64_t id, json_object *req) { char buf [64]; json_object_iter i; json_object *o; kvsdir_t *dir; if (kvs_get_dir (h, &dir, "lwj.%lu", id) < 0) err_exit ("kvs_get_dir (id=%lu)", id); json_object_object_foreachC (req, i) kvsdir_put_obj (dir, i.key, i.val); o = json_object_new_string (ctime_iso8601_now (buf, sizeof (buf))); kvsdir_put_obj (dir, "create-time", o); json_object_put (o); kvsdir_destroy (dir); }
static void dump_kvs_dir (flux_t h, bool ropt, const char *path) { kvsdir_t *dir; kvsitr_t *itr; const char *name; char *key; if (kvs_get_dir (h, &dir, "%s", path) < 0) err_exit ("%s", path); itr = kvsitr_create (dir); while ((name = kvsitr_next (itr))) { key = kvsdir_key_at (dir, name); if (kvsdir_issymlink (dir, name)) { char *link; if (kvs_get_symlink (h, key, &link) < 0) err_exit ("%s", key); printf ("%s -> %s\n", key, link); free (link); } else if (kvsdir_isdir (dir, name)) { if (ropt) dump_kvs_dir (h, ropt, key); else printf ("%s.\n", key); } else { char *json_str; if (kvs_get (h, key, &json_str) < 0) err_exit ("%s", key); dump_kvs_val (key, json_str); free (json_str); } free (key); } kvsitr_destroy (itr); kvsdir_destroy (dir); }