]> www.infradead.org Git - users/dhowells/kafs-client.git/commitdiff
Honour 'thiscell' setting in preload
authorDavid Howells <dhowells@redhat.com>
Tue, 22 Jan 2019 13:58:46 +0000 (13:58 +0000)
committerDavid Howells <dhowells@redhat.com>
Tue, 22 Jan 2019 13:58:46 +0000 (13:58 +0000)
If a defaults section exists in the configuration and this contains a
setting for the workstation's cell, e.g.:

[defaults]
thiscell = example.com

then load this into kernel after the cell list has been preloaded.

Signed-off-by: David Howells <dhowells@redhat.com>
src/include/kafs/cellserv.h
src/lib_cell_lookup.c
src/preload-cells.c

index eec8379253d35321c5fcfc80c68e5d4bcab37269..00e081e3928c3f3c518d463a988f3a6116550584 100644 (file)
@@ -146,6 +146,7 @@ extern int kafs_dns_lookup_vlservers(struct kafs_server_list *vsl,
  */
 extern struct kafs_profile kafs_config_profile;
 extern struct kafs_cell_db *kafs_cellserv_db;
+extern const char *kafs_this_cell;
 extern int kafs_read_config(const char *const *files,
                            struct kafs_report *report);
 extern struct kafs_cell *kafs_lookup_cell(const char *cell_name,
index 65a9a4b47dac2c2c7350f8cab156c78feda8751b..2029707188938589ae40e7e6d8284fcf82cecb02 100644 (file)
@@ -23,6 +23,7 @@ static const char *const kafs_std_config[] = {
 
 struct kafs_profile kafs_config_profile = { .name = "<kafsconfig>" };
 struct kafs_cell_db *kafs_cellserv_db;
+const char *kafs_this_cell;
 
 #define verbose(r, fmt, ...)                                           \
        do {                                                            \
@@ -53,6 +54,26 @@ error:
        return NULL;
 }
 
+/*
+ * Read the [defaults] section.
+ */
+static void kafs_read_defaults(struct kafs_profile *prof, struct kafs_report *report)
+{
+       const struct kafs_profile *def;
+       const char *p;
+
+       def = kafs_profile_find_first_child(prof, kafs_profile_value_is_list, "defaults", report);
+       if (!def) {
+               verbose(report, "Cannot find [defaults] section");
+               return;
+       }
+
+       /* Find the current cell name (thiscell = <cellname>) */
+       p = kafs_profile_get_string(def, "thiscell", report);
+       if (p)
+               kafs_this_cell = p;
+}
+
 /*
  * Read the configuration and initialise the cell database.
  */
@@ -70,6 +91,7 @@ int kafs_read_config(const char *const *files, struct kafs_report *report)
        if (!kafs_cellserv_db)
                return -1;
 
+       kafs_read_defaults(&kafs_config_profile, report);
        return 0;
 }
 
index c387fc3548a6141d4f9fe944928f2785af9849e2..c51bba335e8394688aa06eb757d125355dcc660b 100644 (file)
@@ -68,7 +68,7 @@ int do_preload(const struct kafs_cell_db *db, bool redirect_to_stdout)
 {
        unsigned int i;
        char buf[4096];
-       int fd;
+       int fd, n;
 
        if (!redirect_to_stdout) {
                fd = open("/proc/fs/afs/cells", O_WRONLY);
@@ -82,7 +82,6 @@ int do_preload(const struct kafs_cell_db *db, bool redirect_to_stdout)
 
        for (i = 0; i < db->nr_cells; i++) {
                const struct kafs_cell *cell = db->cells[i];
-               int n;
 
                n = snprintf(buf, sizeof(buf) - 1, "add %s", cell->name);
                if (write(fd, buf, n) != n) {
@@ -105,6 +104,33 @@ int do_preload(const struct kafs_cell_db *db, bool redirect_to_stdout)
                }
        }
 
+       if (kafs_this_cell) {
+               if (!redirect_to_stdout) {
+                       fd = open("/proc/net/afs/rootcell", O_WRONLY);
+                       if (fd == -1) {
+                               _error("Can't open /proc/fs/afs/rootcell: %m");
+                               exit(1);
+                       }
+               }
+
+               n = strlen(kafs_this_cell);
+               if (write(fd, kafs_this_cell, n) != n) {
+                       _error("Can't set root cell '%s': %m", kafs_this_cell);
+                       exit(1);
+               }
+
+               if (!redirect_to_stdout) {
+                       if (close(fd) == -1) {
+                               _error("Can't close /proc/fs/afs/rootcell: %m");
+                               exit(1);
+                       }
+               } else {
+                       if (write(1, "\n", 1) == -1)
+                               perror("stdout");
+               }
+
+       }
+
        exit(0);
 }