From 21d91a2da8ea76d6b29ad2192a7d00a9911b8713 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 14 Mar 2011 12:22:17 +1100 Subject: [PATCH] lafs: add write_dev command 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 --- lib/lafs_add_device.c | 2 +- tools/lafs.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/lafs_add_device.c b/lib/lafs_add_device.c index f8aab6b..819c658 100644 --- a/lib/lafs_add_device.c +++ b/lib/lafs_add_device.c @@ -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; diff --git a/tools/lafs.c b/tools/lafs.c index 3c0ee71..28e0a6e 100644 --- a/tools/lafs.c +++ b/tools/lafs.c @@ -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} }; -- 2.39.5