All of lore.kernel.org
 help / color / mirror / Atom feed
From: wysochanski@sourceware.org <wysochanski@sourceware.org>
To: lvm-devel@redhat.com
Subject: LVM2 lib/metadata/metadata-exported.h lib/meta ...
Date: 28 Jul 2009 15:14:57 -0000	[thread overview]
Message-ID: <20090728151457.9129.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski at sourceware.org	2009-07-28 15:14:57

Modified files:
	lib/metadata   : metadata-exported.h metadata.c 
	liblvm         : lvm_lv.c lvm_vg.c 

Log message:
	Add an open_mode to the vg struct for liblvm - enforce read / write semantics.
	
	For now, a simple way to enforce the read/write semantics is to just save the
	open mode of the VG.  If the caller uses lvm_vg_create, the mode is write.
	The caller using lvm_vg_open can use either read or write to open the VG.
	Once we have this, we enforce the permissions on each API call and don't allow
	a caller to modify a VG that has not been opened properly.
	
	This may be better combined with the locking mode, but I view that as future
	cleanup, past this initial release.  The intial release should enforce the
	basic object semantics though, as described in the lvm.h file.
	
	Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.104&r2=1.105
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.271&r2=1.272
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_lv.c.diff?cvsroot=lvm2&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_vg.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23

--- LVM2/lib/metadata/metadata-exported.h	2009/07/28 13:17:04	1.104
+++ LVM2/lib/metadata/metadata-exported.h	2009/07/28 15:14:56	1.105
@@ -247,6 +247,7 @@
 	 * They have to get cleared on vg_commit.
 	 */
 	struct dm_list removed_pvs;
+	uint32_t open_mode; /* FIXME: read or write - check lock type? */
 
 	/*
 	 * Store result of the last vg_read().
@@ -713,6 +714,7 @@
 uint64_t vg_extent_count(const vg_t *vg);
 uint64_t vg_free_count(const vg_t *vg);
 uint64_t vg_pv_count(const vg_t *vg);
+int vg_check_write_mode(vg_t *vg);
 #define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED)
 
 struct vgcreate_params {
--- LVM2/lib/metadata/metadata.c	2009/07/28 13:17:04	1.271
+++ LVM2/lib/metadata/metadata.c	2009/07/28 15:14:56	1.272
@@ -3042,6 +3042,16 @@
 	return 1;
 }
 
+/* FIXME: remove / combine this with locking? */
+int vg_check_write_mode(vg_t *vg)
+{
+	if (vg->open_mode != 'w') {
+		log_errno(EPERM, "Attempt to modify a read-only VG\n");
+		return 0;
+	}
+	return 1;
+}
+
 /*
  * Performs a set of checks against a VG according to bits set in status
  * and returns FAILED_* bits for those that aren't acceptable.
--- LVM2/liblvm/lvm_lv.c	2009/07/28 13:16:40	1.11
+++ LVM2/liblvm/lvm_lv.c	2009/07/28 15:14:56	1.12
@@ -107,9 +107,10 @@
 	uint64_t extents;
 	struct lv_list *lvl;
 
-	/* FIXME: check for proper VG access */
 	if (vg_read_error(vg))
 		return NULL;
+	if (!vg_check_write_mode(vg))
+		return NULL;
 	memset(&lp, 0, sizeof(lp));
 	extents = extents_from_size(vg->cmd, size, vg->extent_size);
 	_lv_set_default_params(&lp, vg, name, extents);
@@ -130,6 +131,8 @@
 {
 	if (!lv || !lv->vg || vg_read_error(lv->vg))
 		return -1;
+	if (!vg_check_write_mode(lv->vg))
+		return -1;
 	if (!lv_remove_single(lv->vg->cmd, lv, DONT_PROMPT))
 		return -1;
 	return 0;
--- LVM2/liblvm/lvm_vg.c	2009/07/28 13:17:04	1.22
+++ LVM2/liblvm/lvm_vg.c	2009/07/28 15:14:56	1.23
@@ -35,6 +35,7 @@
 		vg_release(vg);
 		return NULL;
 	}
+	vg->open_mode = 'w';
 	return vg;
 }
 
@@ -43,6 +44,9 @@
 	if (vg_read_error(vg))
 		return -1;
 
+	if (!vg_check_write_mode(vg))
+		return -1;
+
 	if (!lock_vol(vg->cmd, VG_ORPHANS, LCK_VG_WRITE)) {
 		log_error("Can't get lock for orphan PVs");
 		return -1;
@@ -72,6 +76,8 @@
 {
 	if (vg_read_error(vg))
 		return -1;
+	if (!vg_check_write_mode(vg))
+		return -1;
 
 	if (!vg_reduce(vg, (char *)device))
 		return -1;
@@ -82,6 +88,8 @@
 {
 	if (vg_read_error(vg))
 		return -1;
+	if (!vg_check_write_mode(vg))
+		return -1;
 
 	if (!vg_set_extent_size(vg, new_size))
 		return -1;
@@ -94,6 +102,8 @@
 
 	if (vg_read_error(vg))
 		return -1;
+	if (!vg_check_write_mode(vg))
+		return -1;
 
 	if (dm_list_empty(&vg->pvs)) {
 		log_error("Volume group %s does not contain any "
@@ -140,6 +150,8 @@
 {
 	if (vg_read_error(vg))
 		return -1;
+	if (!vg_check_write_mode(vg))
+		return -1;
 
 	if (!vg_remove_single(vg))
 		return -1;
@@ -165,6 +177,8 @@
 		vg_release(vg);
 		return NULL;
 	}
+	/* FIXME: combine this with locking ? */
+	vg->open_mode = mode[0];
 
 	return vg;
 }



             reply	other threads:[~2009-07-28 15:14 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-28 15:14 wysochanski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-02-21 12:29 LVM2 lib/metadata/metadata-exported.h lib/meta prajnoha
2010-10-12 16:41 mornfall
2010-06-30 20:03 agk
2010-06-30 18:03 wysochanski
2010-06-29 21:32 wysochanski
2010-06-28 20:40 wysochanski
2010-02-24 18:15 wysochanski
2010-02-24 18:15 wysochanski
2010-02-14  3:21 wysochanski
2010-02-14  3:21 wysochanski
2009-11-01 20:05 wysochanski
2009-11-01 19:51 wysochanski
2009-10-31 17:30 wysochanski
2009-10-05 20:03 wysochanski
2009-10-05 20:02 wysochanski
2009-10-01  1:04 agk
2009-09-14 15:45 wysochanski
2009-09-02 21:39 wysochanski
2009-09-02 21:39 wysochanski
2009-07-28 13:17 wysochanski
2009-07-26  2:34 wysochanski
2009-07-26  1:53 wysochanski
2009-07-15  5:50 mornfall
2009-07-14  2:15 wysochanski
2009-07-10 20:07 wysochanski
2009-07-10 20:05 wysochanski
2009-07-09 10:09 wysochanski
2009-07-09 10:08 wysochanski
2009-07-09 10:07 wysochanski
2009-07-09 10:06 wysochanski
2009-07-09 10:04 wysochanski
2009-07-09 10:03 wysochanski
2009-07-08 14:33 wysochanski
2009-07-01 17:00 wysochanski
2008-06-24 20:10 wysochanski
2008-01-16 19:54 wysochanski
2008-01-15 22:56 wysochanski
2007-12-22  2:13 agk
2007-11-15 22:11 agk
2007-07-23 21:03 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=20090728151457.9129.qmail@sourceware.org \
    --to=wysochanski@sourceware.org \
    --cc=lvm-devel@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.