]> git.neil.brown.name Git - lafs-utils.git/commitdiff
lafs: add write_dev command
authorNeilBrown <neilb@suse.de>
Mon, 14 Mar 2011 01:22:17 +0000 (12:22 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 14 Mar 2011 01:22:17 +0000 (12:22 +1100)
I probably want to make this "write dev" at some stage, so there will
also be "write state" and "write checkpoint"

Signed-off-by: NeilBrown <neilb@suse.de>
lib/lafs_add_device.c
tools/lafs.c

index f8aab6be2e76d368731cfc62b2216b7f819c2e1f..819c65830450d25b005cd566eceba88897950a15 100644 (file)
@@ -60,7 +60,7 @@ struct lafs_device *lafs_add_device(struct lafs *fs, char *devname, int fd,
        dev->fd = fd;
        dev->seq = 1;
        dev->devnum = fs->loaded_devs++;
-       dev->name = devname;
+       dev->name = talloc_strdup(dev, devname);
 
        dev->width = width;
        dev->stride = strideblocks;
index 3c0ee7103b6fdfb3be7fef34b902bf4c6dd8bf06..28e0a6eec476197daa6ffddc04c812d5c7c60cd7 100644 (file)
@@ -959,6 +959,42 @@ static void c_add_device(struct state *st, void **args)
 
 }
 
+/****** WRITE_DEV ******/
+static char help_write_dev[] = "Write devices blocks to one or all devices";
+static struct args args_write_dev[] = {
+       { "DEVNAME", external, -1, {NULL}, "Device to write devblocks to"},
+       { "-all",    flag,      0, {NULL}, "Write to all devices"},
+       TERMINAL_ARG
+};
+static void c_write_dev(struct state *st, void **args)
+{
+       struct lafs_device *dev;
+       int found = 0;
+       if (!args[1] && !args[2]) {
+               printf("write dev: no device given for writing\n");
+               return;
+       }
+
+       for (dev = st->lafs->devs; dev; dev = dev->next) {
+               if (args[2] || strcmp(dev->name, (char*)args[1]) == 0) {
+                       int err = lafs_write_dev(dev);
+                       found = 1;
+                       if (err)
+                               printf("write dev: error when writing to %s\n",
+                                      dev->name);
+                       else if (st->verbose)
+                               printf("Device block written to %s\n", dev->name);
+               }
+       }
+       if (found)
+               return;
+       if (args[2])
+               printf("write dev: no devices exist to write to.\n");
+       else
+               printf("write dev: %s is not a registered device in this LaFS.\n",
+                      (char*)args[1]);
+}
+
 /****** STORE ******/
 static char help_store[] = "Create a file in the LaFS from an external file";
 static struct args args_store[] = {
@@ -990,6 +1026,7 @@ static struct cmd lafs_cmds[] = {
        CMD(quit),
        CMD(reset),
        CMD(store),
+       CMD(write_dev),
        { NULL, NULL, NULL, NULL}
 };