From: "Thomas Maier" <balagi@justmail.de>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "petero2@telia.com" <petero2@telia.com>, "akpm@osdl.org" <akpm@osdl.org>
Subject: [PATCH 3/11] 2.6.18-mm3 pktcdvd: new pkt_find_dev()
Date: Tue, 03 Oct 2006 17:25:07 +0200 [thread overview]
Message-ID: <op.tguo6ngciudtyh@master> (raw)
[-- 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)
next reply other threads:[~2006-10-03 15:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-03 15:25 Thomas Maier [this message]
2006-10-05 19:51 ` [PATCH 3/11] 2.6.18-mm3 pktcdvd: new pkt_find_dev() Peter Osterlund
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=op.tguo6ngciudtyh@master \
--to=balagi@justmail.de \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=petero2@telia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox