public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/11] 2.6.18-mm3 pktcdvd: new pkt_find_dev()
@ 2006-10-03 15:25 Thomas Maier
  2006-10-05 19:51 ` Peter Osterlund
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Maier @ 2006-10-03 15:25 UTC (permalink / raw)
  To: linux-kernel@vger.kernel.org; +Cc: petero2@telia.com, akpm@osdl.org

[-- Attachment #1: Type: text/plain, Size: 621 bytes --]

Hello,

this patch adds a pkt_find_dev() function for reusability and
groups all pkt_find*() functions.
Also pkt_remove_dev() can use now the device id of the mapped
block device to remove the mapping.

http://people.freenet.de/BalaGi/download/pktcdvd-3-util-pkt_find_dev_2.6.18.patch

Note: patch 1/11 and 2/11 of this patch set were applied to 2.6.18-mm2 and
therefore are already in 2.6.18-mm3:
http://people.freenet.de/BalaGi/download/pktcdvd-2-pktdev_major_2.6.18.patch
http://people.freenet.de/BalaGi/download/pktcdvd-1-macro-driver-name_2.6.18.patch


Signed-off-by: Thomas Maier<balagi@justmail.de>

-Thomas Maier

[-- Attachment #2: pktcdvd-3-util-pkt_find_dev_2.6.18.patch --]
[-- Type: application/octet-stream, Size: 2372 bytes --]

diff -urpN 2-pktdev_major/drivers/block/pktcdvd.c 3-util-pkt_find_dev/drivers/block/pktcdvd.c
--- 2-pktdev_major/drivers/block/pktcdvd.c	2006-10-03 11:44:50.000000000 +0200
+++ 3-util-pkt_find_dev/drivers/block/pktcdvd.c	2006-10-03 11:45:17.000000000 +0200
@@ -87,6 +87,41 @@ static struct mutex ctl_mutex;	/* Serial
 static mempool_t *psd_pool;
 
 
+/******************************************************************
+ * utils
+ *****************************************************************/
+
+static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor)
+{
+	if (dev_minor >= MAX_WRITERS)
+		return NULL;
+	return pkt_devs[dev_minor];
+}
+
+/*
+ * find a pktcdvd_device by it's device id and return the index
+ * in the pkt_devs array in *pidx. if ismbd != 0, assume that
+ * devid is the device id of the mapped block device.
+ */
+static struct pktcdvd_device *pkt_find_dev(dev_t devid, int ismbd, int* pidx)
+{
+	int idx;
+	for (idx = 0; idx < MAX_WRITERS; idx++) {
+		struct pktcdvd_device *pd = pkt_devs[idx];
+		if (pd && ((!ismbd && pd->pkt_dev == devid)
+			|| (ismbd && pd->bdev && pd->bdev->bd_dev == devid))) {
+			if (pidx)
+				*pidx = idx;
+			return pd;
+		}
+	}
+	if (pidx)
+		*pidx = 0;
+	return NULL;
+}
+
+/*****************************************************************/
+
 static void pkt_bio_finished(struct pktcdvd_device *pd)
 {
 	BUG_ON(atomic_read(&pd->cdrw.pending_bios) <= 0);
@@ -1996,13 +2031,6 @@ static void pkt_release_dev(struct pktcd
 	pkt_shrink_pktlist(pd);
 }
 
-static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor)
-{
-	if (dev_minor >= MAX_WRITERS)
-		return NULL;
-	return pkt_devs[dev_minor];
-}
-
 static int pkt_open(struct inode *inode, struct file *file)
 {
 	struct pktcdvd_device *pd = NULL;
@@ -2516,14 +2544,14 @@ static int pkt_remove_dev(struct pkt_ctr
 	int idx;
 	dev_t pkt_dev = new_decode_dev(ctrl_cmd->pkt_dev);
 
-	for (idx = 0; idx < MAX_WRITERS; idx++) {
-		pd = pkt_devs[idx];
-		if (pd && (pd->pkt_dev == pkt_dev))
-			break;
-	}
-	if (idx == MAX_WRITERS) {
-		DPRINTK(DRIVER_NAME": dev not setup\n");
-		return -ENXIO;
+	pd = pkt_find_dev(pkt_dev, 0, &idx);
+	if (!pd) {
+		/* maybe pkt_dev is the mapped block device id */
+		pd = pkt_find_dev(pkt_dev, 1, &idx);
+		if (!pd) {
+			DPRINTK(DRIVER_NAME": dev not setup\n");
+			return -ENXIO;
+		}
 	}
 
 	if (pd->refcnt > 0)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-10-05 19:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-03 15:25 [PATCH 3/11] 2.6.18-mm3 pktcdvd: new pkt_find_dev() Thomas Maier
2006-10-05 19:51 ` Peter Osterlund

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox