2.6.18-mm3 pktcdvd: new pkt_find_dev()
PATCH 3/11 2.6.18-mm3 pktcdvd: new pkt_find_dev()
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
-Thomas Maier
drivers/block/pktcdvd.c +43 -15
@@ -87,6 +87,41 @@ static struct mutex ctl_mutex; /* Serialstatic 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 pktcdpkt_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_ctrint 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 )
Quoted 2 lines · Thomas Maier
Also
pkt_remove_dev()can use now the device id of the mapped block device to remove the mapping.
Why would that be desirable? I think it's better to implement this feature in the user space tools and leave the kernel interface simple.
Signature · 2 lines
Peter Osterlund - [email protected] http://web.telia.com/~u89404340