public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: wysochanski@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2/lib/metadata metadata-exported.h metadata.c
Date: Tue, 09 Jun 2009 14:29:00 -0000	[thread overview]
Message-ID: <20090609142912.6297.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2009-06-09 14:29:11

Modified files:
	lib/metadata   : metadata-exported.h metadata.c 

Log message:
	Add vg_lock_newname() library function.
	
	Various tools need to check for existence of a VG before doing something
	(vgsplit, vgrename, vgcreate).  Currently we don't have an interface to
	check for existence, but the existence check is part of the vg_read* call(s).
	This patch is an attempt to pull out some of that functionality into a
	separate function, and hopefully simplify our vg_read interface, and
	move those patches along.
	
	vg_lock_newname() is only concerned about checking whether a vg exists in
	the system.  Unfortunately, we cannot just scan the system, but we must first
	obtain a lock.  Since we are reserving a vgname, we take a WRITE lock on
	the vgname.  Once obtained, we scan the system to ensure the name does
	not exist.  The return codes and behavior is in the function header.
	You might think of this function as similar to an open() call with
	O_CREAT and O_EXCL flags (returns failure with -EEXIST if file already
	exists).
	
	NOTE: I think including the word "lock" in the function name is important,
	as it clearly states the function obtains a lock and makes the code more
	readable, especially when it comes to cleanup / unlocking.  The ultimate
	function name is somewhat open for debate though so later we may rename.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.76&r2=1.77
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.224&r2=1.225

--- LVM2/lib/metadata/metadata-exported.h	2009/06/05 20:00:52	1.76
+++ LVM2/lib/metadata/metadata-exported.h	2009/06/09 14:29:10	1.77
@@ -127,6 +127,8 @@
 #define FAILED_RESIZEABLE	0x00000020U
 #define FAILED_CLUSTERED	0x00000040U
 #define FAILED_ALLOCATION	0x00000080U
+#define FAILED_EXIST		0x00000100U
+#define SUCCESS			0x00000000U
 
 /* Ordered list - see lv_manip.c */
 typedef enum {
@@ -401,6 +403,7 @@
 		       const char *vgid,
 		       uint32_t lock_flags, uint32_t status_flags,
 		       uint32_t misc_flags);
+uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname);
 
 /*
  * Return a handle to VG metadata.
--- LVM2/lib/metadata/metadata.c	2009/06/01 12:43:32	1.224
+++ LVM2/lib/metadata/metadata.c	2009/06/09 14:29:10	1.225
@@ -2909,6 +2909,52 @@
 }
 
 /*
+ * Lock a vgname and/or check for existence.
+ * Takes a WRITE lock on the vgname before scanning.
+ * If scanning fails or vgname found, release the lock.
+ * NOTE: If you find the return codes confusing, you might think of this
+ * function as similar to an open() call with O_CREAT and O_EXCL flags
+ * (open returns fail with -EEXIST if file already exists).
+ *
+ * Returns:
+ * FAILED_LOCKING - Cannot lock name
+ * FAILED_EXIST - VG name already exists - cannot reserve
+ * SUCCESS - VG name does not exist in system and WRITE lock held
+ */
+uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)
+{
+	if (!lock_vol(cmd, vgname, LCK_VG_WRITE)) {
+		return FAILED_LOCKING;
+	}
+
+	/* Find the vgname in the cache */
+	/* If it's not there we must do full scan to be completely sure */
+	if (!fmt_from_vgname(vgname, NULL)) {
+		lvmcache_label_scan(cmd, 0);
+		if (!fmt_from_vgname(vgname, NULL)) {
+			if (memlock()) {
+				/*
+				 * FIXME: Disallow calling this function if
+				 * memlock() is true.
+				 */
+				unlock_vg(cmd, vgname);
+				return FAILED_LOCKING;
+			}
+			lvmcache_label_scan(cmd, 2);
+			if (!fmt_from_vgname(vgname, NULL)) {
+				/* vgname not found after scanning */
+				return SUCCESS;
+			}
+		}
+	}
+
+	/* Found vgname, cannot reserve */
+	unlock_vg(cmd, vgname);
+	return FAILED_EXIST;
+}
+
+
+/*
  * Gets/Sets for external LVM library
  */
 struct id pv_id(const pv_t *pv)


             reply	other threads:[~2009-06-09 14:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-09 14:29 wysochanski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-06-29 22:41 wysochanski
2010-06-28 20:36 wysochanski
2010-05-19 11:52 wysochanski
2010-04-13 17:26 wysochanski
2009-07-26  2:02 wysochanski
2009-07-26  1:53 wysochanski
2009-07-15 17:26 agk
2009-07-15  6:10 mornfall
2009-07-10 21:19 wysochanski
2009-07-08 14:31 wysochanski
2009-07-08 14:28 wysochanski
2009-01-27  1:48 agk
2009-01-27  0:40 agk
2009-01-26 22:13 agk
2008-03-13 22:51 wysochanski

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=20090609142912.6297.qmail@sourceware.org \
    --to=wysochanski@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).