From 3b6a1476538cd2a92f949cd552f4402d9f2f76dd Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Fri, 31 Jul 2009 17:51:45 +0000 Subject: [PATCH] Add udevcomplete and --noudevwait to dmsetup. --- WHATS_NEW | 1 + libdm/.exported_symbols | 2 +- libdm/libdevmapper.h | 2 +- libdm/libdm-common.c | 4 +-- man/dmsetup.8.in | 11 ++++++++ tools/dmsetup.c | 57 ++++++++++++++++++++++++++++++++++++++--- 6 files changed, 70 insertions(+), 7 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index 4cc70bb98..ef7415540 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.51 - ================================ + Add udevcomplete and --noudevwait to dmsetup. Add libdevmapper functions to support synchronisation with udev. Added configure --enable-udev_rules --enable-udev_sync. Added configure --with-udev-prefix --with-udevdir. diff --git a/libdm/.exported_symbols b/libdm/.exported_symbols index c829fa764..d7d89d60c 100644 --- a/libdm/.exported_symbols +++ b/libdm/.exported_symbols @@ -157,6 +157,6 @@ dm_list_next dm_list_size dm_udev_set_sync_support dm_udev_get_sync_support -dm_udev_notify +dm_udev_complete dm_udev_wait dm_udev_cleanup diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index 6bf9dab60..f1692f3ef 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -1018,7 +1018,7 @@ int dm_cookie_supported(void); */ void dm_udev_set_sync_support(int sync_with_udev); int dm_udev_get_sync_support(void); -int dm_udev_notify(uint32_t cookie); +int dm_udev_complete(uint32_t cookie); int dm_udev_wait(uint32_t cookie); int dm_udev_cleanup(uint32_t cookie); diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c index b488b02e2..bc365b6ee 100644 --- a/libdm/libdm-common.c +++ b/libdm/libdm-common.c @@ -789,7 +789,7 @@ int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie) return 1; } -int dm_udev_notify(uint32_t cookie) +int dm_udev_complete(uint32_t cookie) { return 1; } @@ -983,7 +983,7 @@ bad: return 0; } -int dm_udev_notify(uint32_t cookie) +int dm_udev_complete(uint32_t cookie) { int semid; diff --git a/man/dmsetup.8.in b/man/dmsetup.8.in index 4fcb0845e..c22f7978e 100644 --- a/man/dmsetup.8.in +++ b/man/dmsetup.8.in @@ -64,6 +64,9 @@ dmsetup \- low level logical volume management .B dmsetup mknodes .I [device_name] .br +.B dmsetup udevcomplete +.I cookie +.br .B dmsetup targets .br .B dmsetup version @@ -108,6 +111,9 @@ Tell the kernel not to supply the open reference count for the device. .IP \fB--notable .br When creating a device, don't load any table. +.IP \fB--noudevsync +Do not synchronise with udev when creating, renaming or removing devices. +.br .IP \fB-o|--options .br Specify which fields to display. @@ -280,6 +286,11 @@ is displayed. .IP \fBtargets .br Displays the names and versions of the currently-loaded targets. +.IP \fBudevcomplete +.I cookie +.br +Wake any processes that are waiting for udev to complete processing the specified cookie. +.br .IP \fBversion .br Outputs version information. diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 94ac9fd8c..e189cc88c 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -119,6 +119,7 @@ enum { NOLOCKFS_ARG, NOOPENCOUNT_ARG, NOTABLE_ARG, + NOUDEVSYNC_ARG, OPTIONS_ARG, READAHEAD_ARG, ROWS_ARG, @@ -540,6 +541,7 @@ static int _create(int argc, char **argv, void *data __attribute((unused))) int r = 0; struct dm_task *dmt; const char *file = NULL; + uint32_t cookie = 0; if (argc == 3) file = argv[2]; @@ -582,8 +584,16 @@ static int _create(int argc, char **argv, void *data __attribute((unused))) _read_ahead_flags)) goto out; - if (!dm_task_run(dmt)) + if (_switches[NOTABLE_ARG]) + dm_udev_set_sync_support(0); + + if (!dm_task_set_cookie(dmt, &cookie) || + !dm_task_run(dmt)) { + (void) dm_udev_cleanup(cookie); goto out; + } + + dm_udev_wait(cookie); r = 1; @@ -600,6 +610,7 @@ static int _rename(int argc, char **argv, void *data __attribute((unused))) { int r = 0; struct dm_task *dmt; + uint32_t cookie = 0; if (!(dmt = dm_task_create(DM_DEVICE_RENAME))) return 0; @@ -614,8 +625,13 @@ static int _rename(int argc, char **argv, void *data __attribute((unused))) if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt)) goto out; - if (!dm_task_run(dmt)) + if (!dm_task_set_cookie(dmt, &cookie) || + !dm_task_run(dmt)) { + (void) dm_udev_cleanup(cookie); goto out; + } + + dm_udev_wait(cookie); r = 1; @@ -740,6 +756,19 @@ static int _splitname(int argc, char **argv, void *data __attribute((unused))) return r; } +static int _udevcomplete(int argc, char **argv, void *data __attribute((unused))) +{ + uint32_t cookie; + char *p; + + if (!(cookie = (uint32_t) strtoul(argv[1], &p, 0)) || *p) { + err("Incorrect cookie value"); + return 0; + } + + return dm_udev_complete(cookie); +} + static int _version(int argc __attribute((unused)), char **argv __attribute((unused)), void *data __attribute((unused))) { char version[80]; @@ -757,6 +786,9 @@ static int _version(int argc __attribute((unused)), char **argv __attribute((unu static int _simple(int task, const char *name, uint32_t event_nr, int display) { + uint32_t cookie = 0; + int udev_wait_flag = task == DM_DEVICE_RESUME || + task == DM_DEVICE_REMOVE; int r = 0; struct dm_task *dmt; @@ -784,8 +816,20 @@ static int _simple(int task, const char *name, uint32_t event_nr, int display) _read_ahead_flags)) goto out; + if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie)) { + (void) dm_udev_cleanup(cookie); + goto out; + } + r = dm_task_run(dmt); + if (udev_wait_flag) { + if (r) + (void) dm_udev_wait(cookie); + else + (void) dm_udev_cleanup(cookie); + } + if (r && display && _switches[VERBOSE_ARG]) r = _display_info(dmt); @@ -2261,6 +2305,7 @@ static struct command _commands[] = { {"table", "[] [--target ] [--showkeys]", 0, 1, _status}, {"wait", " []", 0, 2, _wait}, {"mknodes", "[]", 0, 1, _mknodes}, + {"udevcomplete", "", 1, 1, _udevcomplete}, {"targets", "", 0, 0, _targets}, {"version", "", 0, 0, _version}, {"setgeometry", " ", 5, 5, _setgeometry}, @@ -2275,7 +2320,7 @@ static void _usage(FILE *out) fprintf(out, "Usage:\n\n"); fprintf(out, "dmsetup [--version] [-v|--verbose [-v|--verbose ...]]\n" " [-r|--readonly] [--noopencount] [--nolockfs]\n" - " [--readahead [+]|auto|none]\n" + " [--noudevsync] [--readahead [+]|auto|none]\n" " [-c|-C|--columns] [-o ] [-O|--sort ]\n" " [--nameprefixes] [--noheadings] [--separator ]\n\n"); for (i = 0; _commands[i].name; i++) @@ -2639,6 +2684,7 @@ static int _process_switches(int *argc, char ***argv, const char *dev_dir) {"nolockfs", 0, &ind, NOLOCKFS_ARG}, {"noopencount", 0, &ind, NOOPENCOUNT_ARG}, {"notable", 0, &ind, NOTABLE_ARG}, + {"noudevsync", 0, &ind, NOUDEVSYNC_ARG}, {"options", 1, &ind, OPTIONS_ARG}, {"readahead", 1, &ind, READAHEAD_ARG}, {"rows", 0, &ind, ROWS_ARG}, @@ -2747,6 +2793,8 @@ static int _process_switches(int *argc, char ***argv, const char *dev_dir) _switches[UUID_ARG]++; _uuid = optarg; } + if (ind == NOUDEVSYNC_ARG) + _switches[NOUDEVSYNC_ARG]++; if (c == 'G' || ind == GID_ARG) { _switches[GID_ARG]++; _int_args[GID_ARG] = atoi(optarg); @@ -2888,6 +2936,9 @@ int main(int argc, char **argv) if (_switches[COLS_ARG] && !_report_init(c)) goto out; + if (_switches[NOUDEVSYNC_ARG]) + dm_udev_set_sync_support(0); + doit: if (!c->fn(argc, argv, NULL)) { fprintf(stderr, "Command failed\n"); -- 2.43.5