From df520f126531482afa749423a6e42424c058a7e1 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 14 Dec 2001 13:30:04 +0000 Subject: [PATCH] o Include dmsetup man page in build o Allow pathname in dmsetup device arg o Generated patches for 0.90.02 --- libdm/libdm-common.c | 40 +++++++++++++++++---- man/dmsetup.8.in | 86 ++++++++++++++++++++++---------------------- tools/dmsetup.c | 2 +- 3 files changed, 78 insertions(+), 50 deletions(-) diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index 70372ce3a..f108e91d2 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -49,6 +49,15 @@ void dm_log_init(dm_log_fn fn) _log = fn; } +void _build_dev_path(char *buffer, size_t len, const char *dev_name) +{ + /* If there's a /, assume caller knows what they're doing */ + if (strchr(dev_name, '/')) + snprintf(buffer, len, "%s", dev_name); + else + snprintf(buffer, len, "/dev/%s/%s", DM_DIR, dev_name); +} + struct dm_task *dm_task_create(int type) { struct dm_task *dmt = malloc(sizeof(*dmt)); @@ -66,10 +75,34 @@ struct dm_task *dm_task_create(int type) int dm_task_set_name(struct dm_task *dmt, const char *name) { + char *pos; + char path[PATH_MAX]; + struct stat st1, st2; + if (dmt->dev_name) free(dmt->dev_name); - return (dmt->dev_name = strdup(name)) ? 1 : 0; + /* If path was supplied, remove it if it points to the same device + * as its last component. + */ + if ((pos = strrchr(name, '/'))) { + snprintf(path, sizeof(path), "/dev/%s/%s", DM_DIR, pos + 1); + + if (stat(name, &st1) || stat(path, &st2) || + !(st1.st_dev == st2.st_dev)) { + log("dm_task_set_name: Device %s not found", name); + return 0; + } + + name = pos + 1; + } + + if (!(dmt->dev_name = strdup(name))) { + log("dm_task_set_name: strdup(%s) failed", name); + return 0; + } + + return 1; } int dm_task_add_target(struct dm_task *dmt, @@ -93,11 +126,6 @@ int dm_task_add_target(struct dm_task *dmt, return 1; } -void _build_dev_path(char *buffer, size_t len, const char *dev_name) -{ - snprintf(buffer, len, "/dev/%s/%s", DM_DIR, dev_name); -} - int add_dev_node(const char *dev_name, dev_t dev) { char path[PATH_MAX]; diff --git a/man/dmsetup.8.in b/man/dmsetup.8.in index 7d2626acd..78fdfb97b 100644 --- a/man/dmsetup.8.in +++ b/man/dmsetup.8.in @@ -4,91 +4,90 @@ dmsetup \- low level logical volume management .SH SYNOPSIS .ad l .B dmsetup create -.I +.I device_name table_file .br .B dmsetup remove -.I +.I device_name .br .B dmsetup suspend -.I +.I device_name .br .B dmsetup resume -.I +.I device_name .br .B dmsetup reload -.I
+.I device_name table_file .br .B dmsetup info -.I +.I device_name .ad b .SH DESCRIPTION -dmsetup is used to manage mapped devices using the device-mapper -driver. Devices are created by loading a table that gives a target -for ranges of sectors in the logical device. +dmsetup manages logical devices that use the device-mapper driver. +Devices are created by loading a table that specifies a target for +each sector in the logical device. -The first argument to dmsetup is a command, after this the mapped -device name (not the full path). -.SH Commands -.RS +The first argument to dmsetup is a command. +The second argument is the logical device name. +.SH COMMANDS .IP \fBcreate -.I
+.I device_name table_file .br Attempts to create a device using the table file given. If successful a device will appear as /dev/device-mapper/. See below for information on the table file format. .IP \fBremove -.I +.I device_name .br Removes the device .IP \fBsuspend -.I +.I device_name .br -Suspends a device, there are two parts to this. Firstly any -io that has already been mapped by the device, but has not yet -completed will be flushed. Secondly any further io to that +Suspends a device. Any I/O that has already been mapped by the device +but has not yet completed will be flushed. Any further I/O to that device will be postponed for as long as the device is suspended. .IP \fBresume -.I +.I device_name .br -Un-suspends a device, postponed io now get's re-queued for processing. +Un-suspends a device. Postponed I/O now gets re-queued for processing. .IP \fBreload -.I
+.I device_name table_file .br This command will only work if a device is in the suspended state. -It allows the user to change the mapping table for an existing device. +It changes the mapping table for an existing device. .IP \fBinfo -.I +.I device_name .br -Output's some brief information about the device in the form: +Outputs some brief information about the device in the form: .br - + SUSPENDED|ACTIVE .br - + open_count .br -, + major,minor .br - -.SH Table format -Each line of the table specifies a single target, and is of the form: + target_count +.SH TABLE FORMAT +Each line of the table specifies a single target and is of the form: .br - + logical_start_sector num_sectors target_type target_args .br -At the moment there are 3 simple target types available (though your -system may have more in the form of modules). +.br +At the moment there are 3 simple target types available - though your +system might have more in the form of modules. .IP \fBlinear -.I +.I destination_device start_sector .br The traditional linear mapping. .IP \fBstriped -.I [ ]+ +.I num_stripes chunk_size [destination start_sector]+ .br -Creates a striped area, +Creates a striped area. .br -eg, striped 2 32 /dev/hda1 0 /dev/hdb1 0 - will map the first chunk (16k) as follows: +e.g. striped 2 32 /dev/hda1 0 /dev/hdb1 0 +will map the first chunk (16k) as follows: .br LV chunk 1 -> hda1, chunk 1 .br @@ -103,15 +102,16 @@ eg, striped 2 32 /dev/hda1 0 /dev/hdb1 0 .IP \fBio-err .br -Errors any io that goes to this area. Useful for testing or -creating devices with holes in them. +Errors any I/O that goes to this area. Useful for testing or +for creating devices with holes in them. -.SH Examples +.SH EXAMPLES # A table to join two disks together .br +.br 0 1028160 linear /dev/hda 0 .br 1028160 3903762 linear /dev/hdb 0 @@ -129,4 +129,4 @@ creating devices with holes in them. 2056320 2875602 linear /dev/hdb 1028160 .SH AUTHORS -Original version: Joe Thornber (thornber@sistina.com) \ No newline at end of file +Original version: Joe Thornber (thornber@sistina.com) diff --git a/tools/dmsetup.c b/tools/dmsetup.c index cce4e4e0c..a2adb00a5 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -249,7 +249,7 @@ int main(int argc, char **argv) } if (!c->fn(argc - 1, argv + 1)) { - //fprintf(stderr, "Command failed\n"); + fprintf(stderr, "Command failed\n"); exit(1); } -- 2.43.5