public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: agk@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2 ./WHATS_NEW_DM libdm/ioctl/libdm-iface.c
Date: Fri, 25 Mar 2011 23:50:00 -0000	[thread overview]
Message-ID: <20110325235036.26858.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2011-03-25 23:50:35

Modified files:
	.              : WHATS_NEW_DM 
	libdm/ioctl    : libdm-iface.c 

Log message:
	Use hard-coded /dev/mapper/control details for 2.6.36+ kernels and simplify
	associated code.  (Some obscure configurations that happened to work before
	are no longer supported.)

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW_DM.diff?cvsroot=lvm2&r1=1.457&r2=1.458
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/ioctl/libdm-iface.c.diff?cvsroot=lvm2&r1=1.102&r2=1.103

--- LVM2/WHATS_NEW_DM	2011/03/18 13:21:03	1.457
+++ LVM2/WHATS_NEW_DM	2011/03/25 23:50:35	1.458
@@ -1,5 +1,7 @@
 Version 1.02.64 - 
 ===================================
+  Streamline /dev/mapper/control node code for common cases.
+  Use hard-coded dm control node device number for 2.6.36 kernels and above.
   Improve stack debug reporting in dm_task_create().
   Fallback to control node creation only if node doesn't exist yet.
   Change dm_hash API for binary data to accept const void *key.
--- LVM2/libdm/ioctl/libdm-iface.c	2011/03/20 02:00:52	1.102
+++ LVM2/libdm/ioctl/libdm-iface.c	2011/03/25 23:50:35	1.103
@@ -228,7 +228,7 @@
 }
 
 /*
- * Returns 1 if exists; 0 if it doesn't; -1 if it's wrong
+ * Returns 1 if it exists on returning; 0 if it doesn't; -1 if it's wrong.
  */
 static int _control_exists(const char *control, uint32_t major, uint32_t minor)
 {
@@ -267,8 +267,15 @@
 	int ret;
 	mode_t old_umask;
 
-	if (!major)
-		return 0;
+	/*
+	 * Return if the control already exists with intended major/minor
+	 * or there's an error unlinking an apparently incorrect one.
+	 */
+	ret = _control_exists(control, major, minor);
+	if (ret == -1)
+		return 0;	/* Failed to unlink existing incorrect node */
+	if (ret)
+		return 1;	/* Already exists and correct */
 
 	(void) dm_prepare_selinux_context(dm_dir(), S_IFDIR);
 	old_umask = umask(DM_DEV_DIR_UMASK);
@@ -359,14 +366,9 @@
 	}
 }
 
-static int _open_and_assign_control_fd(const char *control,
-				       int ignore_nodev)
+static int _open_and_assign_control_fd(const char *control)
 {
-	_close_control_fd();
-
 	if ((_control_fd = open(control, O_RDWR)) < 0) {
-		if (ignore_nodev && errno == ENODEV)
-			return 1;
 		log_sys_error("open", control);
 		return 0;
 	}
@@ -378,8 +380,8 @@
 {
 #ifdef DM_IOCTLS
 	char control[PATH_MAX];
-	uint32_t major = 0, minor;
-	int dm_mod_autoload_support, needs_open;
+	uint32_t major = MISC_MAJOR;
+	uint32_t minor = MAPPER_CTRL_MINOR;
 
 	if (_control_fd != -1)
 		return 1;
@@ -390,63 +392,27 @@
 	snprintf(control, sizeof(control), "%s/%s", dm_dir(), DM_CONTROL_NODE);
 
 	/*
-	 * dm-mod autoloading is supported since kernel 2.6.36.
-	 * Udev daemon will try to read modules.devname file extracted
-	 * by depmod and create any static nodes needed.
-	 * The /dev/mapper/control node can be created and prepared this way.
-	 * First access to such node should load dm-mod module automatically.
-	 */
-	dm_mod_autoload_support = KERNEL_VERSION(_kernel_major, _kernel_minor,
-				  _kernel_release) >= KERNEL_VERSION(2, 6, 36);
-
-	/*
-	 *  If dm-mod autoloading is supported and the control node exists
-	 *  already try to open it now. This should autoload dm-mod module.
-	 */
-	if (dm_mod_autoload_support) {
-		if (!_get_proc_number(PROC_DEVICES, MISC_NAME, &major))
-			/* If major not found, just fallback to hardcoded value. */
-			major = MISC_MAJOR;
-
-		/* Recreate the node with correct major and minor if needed. */
-		if (!_control_exists(control, major, MAPPER_CTRL_MINOR) &&
-		    !_create_control(control, major, MAPPER_CTRL_MINOR))
-			goto error;
-
-		/* Fallback to old code only if control node doesn't exist */
-		if (!_open_and_assign_control_fd(control, 1))
-			goto error;
-	}
-
-	/*
-	 * Get major and minor number assigned for the control node.
-	 * In case we make use of the module autoload support, this
-	 * information should be accessible now as well.
+	 * Prior to 2.6.36 the minor number should be looked up in /proc.
 	 */
-	if (!_control_device_number(&major, &minor))
-		log_error("Is device-mapper driver missing from kernel?");
+	if ((KERNEL_VERSION(_kernel_major, _kernel_minor, _kernel_release) <
+	     KERNEL_VERSION(2, 6, 36)) &&
+	    !_control_device_number(&major, &minor))
+		goto_bad;
 
 	/*
-	 * Check the control node and its major and minor number.
-	 * If there's anything wrong, remove the old node and create
-	 * a correct one.
+	 * Create the node with correct major and minor if not already done.
+	 * Udev may already have created /dev/mapper/control
+	 * from the modules.devname file generated by depmod.
 	 */
-	if ((needs_open = !_control_exists(control, major, minor)) &&
-	    !_create_control(control, major, minor)) {
-		_close_control_fd();
-		goto error;
-	}
+	if (!_create_control(control, major, minor))
+		goto_bad;
 
 	/*
-	 * For older kernels without dm-mod autoloading support, we always
-	 * need to open the control node here - we still haven't done that!
-	 * For newer kernels with dm-mod autoloading, we open it only if the
-	 * node was recreated and corrected in previous step.
+	 * As of 2.6.36 kernels, the open can trigger autoloading dm-mod.
 	 */
-	if ((!dm_mod_autoload_support || needs_open) &&
-	     !_open_and_assign_control_fd(control, 0))
-		goto error;
-
+	if (!_open_and_assign_control_fd(control))
+		goto_bad;
+	
 	if (!_create_dm_bitset()) {
 		log_error("Failed to set up list of device-mapper major numbers");
 		return 0;
@@ -454,8 +420,10 @@
 
 	return 1;
 
-error:
+bad:
 	log_error("Failure to communicate with kernel device-mapper driver.");
+	if (!geteuid())
+		log_error("Check that device-mapper is available in the kernel.");
 	return 0;
 #else
 	return 1;


             reply	other threads:[~2011-03-25 23:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-25 23:50 agk [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-03-01 10:07 zkabelac
2012-02-15 12:17 prajnoha
2012-02-08 12:59 zkabelac
2012-02-08 11:25 zkabelac
2011-11-08 17:32 snitzer
2011-10-20 10:38 zkabelac
2011-09-13 15:13 prajnoha
2011-08-11 20:49 zkabelac
2011-07-24 23:59 agk
2011-07-02  1:17 agk
2011-06-09 15:07 mbroz
2011-03-08 22:43 zkabelac
2011-03-01 23:27 agk
2011-02-21 16:26 snitzer
2010-08-18 13:11 prajnoha
2010-05-13 13:31 mbroz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110325235036.26858.qmail@sourceware.org \
    --to=agk@sourceware.org \
    --cc=lvm-devel@redhat.com \
    --cc=lvm2-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).