From b44de841ff453ed2ca69d3222b725705cef1000e Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Fri, 4 Feb 2011 22:17:54 +0000 Subject: [PATCH] Add configure option --with-device-nodes-on Make configurable default behaviour how to deal with device node creates. With udev system natural options should be 'resume'. For older systems where user expect there is node in /dev/mapper immediately after dmsetup create --notable - use 'create' FIXME: Code needs fixing passing this flag through udev cookie. --- configure | 26 ++++++++++++++++++++++++++ configure.in | 13 +++++++++++++ lib/misc/configure.h.in | 3 +++ tools/dmsetup.c | 32 ++++++++++++++++++++++++-------- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 781755aeb..705479da8 100755 --- a/configure +++ b/configure @@ -788,6 +788,7 @@ with_group with_device_uid with_device_gid with_device_mode +with_device_nodes_on enable_lvm1_fallback with_lvm1 with_pool @@ -1526,6 +1527,8 @@ Optional Packages: --with-device-uid=UID set the owner used for new device nodes [[UID=0]] --with-device-gid=GID set the group used for new device nodes [[GID=0]] --with-device-mode=MODE set the mode used for new device nodes [[MODE=0600]] + --with-device-nodes-on=ON + create nodes on resume or create [[ON=resume]] --with-lvm1=TYPE LVM1 metadata support: internal/shared/none [[TYPE=internal]] --with-pool=TYPE GFS pool read-only support: internal/shared/none @@ -6711,6 +6714,29 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DM_DEVICE_MODE" >&5 $as_echo "$DM_DEVICE_MODE" >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking when to create device nodes" >&5 +$as_echo_n "checking when to create device nodes... " >&6; } + +# Check whether --with-device-nodes-on was given. +if test "${with_device_nodes_on+set}" = set; then : + withval=$with_device_nodes_on; ADD_NODE=$withval +else + ADD_NODE=resume +fi + +case "$ADD_NODE" in + resume) add_on=DM_ADD_NODE_ON_RESUME;; + create) add_on=DM_ADD_NODE_ON_CREATE;; + *) as_fn_error $? "--with-device-nodes-on parameter invalid" "$LINENO" 5;; +esac +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: on $ADD_NODE" >&5 +$as_echo "on $ADD_NODE" >&6; } + +cat >>confdefs.h <<_ACEOF +#define DEFAULT_DM_ADD_NODE $add_on +_ACEOF + + ################################################################################ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable lvm1 fallback" >&5 $as_echo_n "checking whether to enable lvm1 fallback... " >&6; } diff --git a/configure.in b/configure.in index b58a6bac8..c531c8a5c 100644 --- a/configure.in +++ b/configure.in @@ -213,6 +213,19 @@ AC_ARG_WITH(device-mode, DM_DEVICE_MODE=$withval, DM_DEVICE_MODE=0600) AC_MSG_RESULT($DM_DEVICE_MODE) +AC_MSG_CHECKING(when to create device nodes) +AC_ARG_WITH(device-nodes-on, + AC_HELP_STRING([--with-device-nodes-on=ON], + [create nodes on resume or create [[ON=resume]]]), + ADD_NODE=$withval, ADD_NODE=resume) +case "$ADD_NODE" in + resume) add_on=DM_ADD_NODE_ON_RESUME;; + create) add_on=DM_ADD_NODE_ON_CREATE;; + *) AC_MSG_ERROR([--with-device-nodes-on parameter invalid]);; +esac +AC_MSG_RESULT(on $ADD_NODE) +AC_DEFINE_UNQUOTED([DEFAULT_DM_ADD_NODE], $add_on, [Define default node creation behavior with dmsetup create]) + ################################################################################ dnl -- LVM1 tool fallback option AC_MSG_CHECKING(whether to enable lvm1 fallback) diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in index c75a1812f..65dd46b78 100644 --- a/lib/misc/configure.h.in +++ b/lib/misc/configure.h.in @@ -35,6 +35,9 @@ /* Default data alignment. */ #undef DEFAULT_DATA_ALIGNMENT +/* Define default node creation behavior with dmsetup create */ +#undef DEFAULT_DM_ADD_NODE + /* Name of default locking directory. */ #undef DEFAULT_LOCK_DIR diff --git a/tools/dmsetup.c b/tools/dmsetup.c index 85d2060d4..86937f00b 100644 --- a/tools/dmsetup.c +++ b/tools/dmsetup.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. * Copyright (C) 2005-2007 NEC Corporation * * This file is part of the device-mapper userspace tools. @@ -507,6 +507,22 @@ static int _set_task_device(struct dm_task *dmt, const char *name, int optional) return 1; } +static int _set_task_add_node(struct dm_task *dmt) +{ + if (!dm_task_set_add_node(dmt, DEFAULT_DM_ADD_NODE)) + return 0; + + if (_switches[ADD_NODE_ON_RESUME_ARG] && + !dm_task_set_add_node(dmt, DM_ADD_NODE_ON_RESUME)) + return 0; + + if (_switches[ADD_NODE_ON_CREATE_ARG] && + !dm_task_set_add_node(dmt, DM_ADD_NODE_ON_CREATE)) + return 0; + + return 1; +} + static int _load(int argc, char **argv, void *data __attribute__((unused))) { int r = 0; @@ -626,13 +642,9 @@ static int _create(int argc, char **argv, void *data __attribute__((unused))) udev_flags |= DM_UDEV_DISABLE_DM_RULES_FLAG | DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG; - if (_switches[ADD_NODE_ON_RESUME_ARG] && - !dm_task_set_add_node(dmt, DM_ADD_NODE_ON_RESUME)) - goto out; - if (_switches[ADD_NODE_ON_CREATE_ARG] && - !dm_task_set_add_node(dmt, DM_ADD_NODE_ON_CREATE)) - goto out; + if (!_set_task_add_node(dmt)) + goto out; if (_udev_cookie) { cookie = _udev_cookie; @@ -1206,6 +1218,10 @@ static int _simple(int task, const char *name, uint32_t event_nr, int display) if (_switches[NOLOCKFS_ARG] && !dm_task_skip_lockfs(dmt)) goto out; + /* FIXME: needs to coperate with udev */ + if (!_set_task_add_node(dmt)) + goto out; + if (_switches[READAHEAD_ARG] && !dm_task_set_read_ahead(dmt, _int_args[READAHEAD_ARG], _read_ahead_flags)) @@ -2709,7 +2725,7 @@ static struct command _commands[] = { {"remove", "[-f|--force] ", 0, 1, _remove}, {"remove_all", "[-f|--force]", 0, 0, _remove_all}, {"suspend", "[--noflush] ", 0, 1, _suspend}, - {"resume", "", 0, 1, _resume}, + {"resume", " [{--addnodeonresume|--addnodeoncreate}]", 0, 1, _resume}, {"load", " []", 0, 2, _load}, {"clear", "", 0, 1, _clear}, {"reload", " []", 0, 2, _load}, -- 2.43.5