[PATCH 6/6] dm ioctl: introduce find_device_noinit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Factor all appropriate consumers of __find_device_hash_cell() to use
find_device_noinit().

Signed-off-by: Mike Snitzer <snitzer@xxxxxxxxxx>
---
 drivers/md/dm-ioctl.c |   51 +++++++++++++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 25 deletions(-)

Index: linux-2.6/drivers/md/dm-ioctl.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-ioctl.c
+++ linux-2.6/drivers/md/dm-ioctl.c
@@ -718,23 +718,40 @@ static struct mapped_device *find_device
 	return md;
 }
 
+static struct mapped_device *find_device_noinit(struct dm_ioctl *param)
+{
+	struct hash_cell *hc;
+	struct mapped_device *md = NULL;
+
+	down_write(&_hash_lock);
+	hc = __find_device_hash_cell(param);
+	if (hc)
+		md = hc->md;
+	else
+		DMWARN("device doesn't appear to be in the dev hash table.");
+	up_write(&_hash_lock);
+
+	return md;
+}
+
 static int dev_remove(struct dm_ioctl *param, size_t param_size)
 {
 	struct hash_cell *hc;
 	struct mapped_device *md;
 	int r;
 
-	down_write(&_hash_lock);
-	hc = __find_device_hash_cell(param);
+	md = find_device_noinit(param);
+	if (!md)
+		return -ENXIO;
 
+	down_write(&_hash_lock);
+	hc = dm_get_verified_mdptr(md);
 	if (!hc) {
-		DMWARN("device doesn't appear to be in the dev hash table.");
 		up_write(&_hash_lock);
+		dm_put(md);
 		return -ENXIO;
 	}
 
-	md = hc->md;
-
 	/*
 	 * Ensure the device is not open and nothing further can open it.
 	 */
@@ -872,17 +889,9 @@ static int do_resume(struct dm_ioctl *pa
 	struct mapped_device *md;
 	struct dm_table *new_map, *old_map = NULL;
 
-	down_write(&_hash_lock);
-
-	hc = __find_device_hash_cell(param);
-	if (!hc) {
-		DMWARN("device doesn't appear to be in the dev hash table.");
-		up_write(&_hash_lock);
+	md = find_device_noinit(param);
+	if (!md)
 		return -ENXIO;
-	}
-
-	md = hc->md;
-	up_write(&_hash_lock);
 
 	dm_lock_resume(md);
 
@@ -1271,17 +1280,9 @@ static int table_clear(struct dm_ioctl *
 	struct mapped_device *md;
 	struct dm_table *live_table;
 
-	down_write(&_hash_lock);
-
-	hc = __find_device_hash_cell(param);
-	if (!hc) {
-		DMWARN("device doesn't appear to be in the dev hash table.");
-		up_write(&_hash_lock);
+	md = find_device_noinit(param);
+	if (!md)
 		return -ENXIO;
-	}
-
-	md = hc->md;
-	up_write(&_hash_lock);
 
 	dm_lock_resume(md);
 	dm_lock_md_type(md); /* May need to clear md's type */

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel

[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux