pvSCSI : Fix many points of backend/frontend driver
PATCH 2/4 pvSCSI : Fix many points of backend/frontend driver
Please refer following Mr. Steven's mail posted on June 24th.
Message-ID: <[email protected]>
Message-ID: <[email protected]>
-----
Jun Kamada
# HG changeset patch
# User [email protected]
# Date 1215060391 -32400
# Node ID e235e0bc18ab3773c3556703c5f37457c58016af # Parent 3132ef07eecf3f7d57bd6659d8f9ecf6f13421f5
pvscsi: Fix attach, detach
drivers/xen/scsiback/common.h +3 -3
@@ -92,7 +92,7 @@ struct vscsibk_info {grant_ref_t shmem_ref;spinlock_t ring_lock; -atomic_t refcnt; +atomic_t nr_unreplied_reqs;spinlock_t v2p_lock;struct list_head v2p_entry_lists;
@@ -133,10 +133,10 @@ typedef struct { -#define scsiback_get (_b) (atomic_inc(&(_b)->refcnt)) +#define scsiback_get (_b) (atomic_inc(&(_b)->nr_unreplied_reqs))#define scsiback_put (_b) \ do { \ - if (atomic_dec_and_test(&(_b)->refcnt)) \ + if (atomic_dec_and_test(&(_b)->nr_unreplied_reqs)) \ wake_up(&(_b)->waiting_to_free);\ } while (0)
drivers/xen/scsiback/interface.c +6 -8
@@ -52,7 +52,7 @@ struct vscsibk_info *vscsibk_info_alloc(memset (info,0 ,sizeof (*info)); info->domid = domid;spin_lock_init (&info->ring_lock); -atomic_set (&info->refcnt,1 ); +atomic_set (&info->nr_unreplied_reqs,0 );init_waitqueue_head (&info->wq);init_waitqueue_head (&info->waiting_to_free);
@@ -104,7 +104,7 @@ int scsiback_init_sring(struct vscsibk_iif (info->irq) {printk (KERN_ERR "scsiback: Already connected through?\n" ); -return 0 ; +return -1 ; } info->ring_area =alloc_vm_area (PAGE_SIZE );
@@ -126,7 +126,7 @@ int scsiback_init_sring(struct vscsibk_i goto unmap_page; info->irq = err; - +return 0 ; unmap_page:
@@ -144,9 +144,8 @@ void scsiback_disconnect(struct vscsibk_ info->kthread =NULL ; } -atomic_dec (&info->refcnt); -wait_event (info->waiting_to_free,atomic_read (&info->refcnt) ==0 ); -atomic_inc (&info->refcnt); +wait_event (info->waiting_to_free, +atomic_read (&info->nr_unreplied_reqs) ==0 );if (info->irq) {unbind_from_irqhandler (info->irq, info);
@@ -162,8 +161,7 @@ void scsiback_disconnect(struct vscsibk_void scsiback_free (struct vscsibk_info *info) { -if (atomic_dec_and_test (&info->refcnt)) -kmem_cache_free (scsiback_cachep, info); +kmem_cache_free (scsiback_cachep, info); }int __init scsiback_interface_init (void )
drivers/xen/scsiback/scsiback.c +54 -52
273 lines not on this page · raw message
drivers/xen/scsiback/translate.c +4 -2
@@ -71,14 +71,14 @@ int scsiback_add_translation_entry(struc }/* Create a new translation entry and add to the list */ -if ((new =kmalloc (sizeof (struct v2p_entry ),GFP_KERNEL )) ==NULL ) { +if ((new =kmalloc (sizeof (struct v2p_entry ),GFP_ATOMIC )) ==NULL ) {printk (KERN_ERR "scsiback: %s: kmalloc() error.\n" , __FUNCTION__); err = -ENOMEM ; goto out; } new->v = *v; new->sdev = sdev; -list_add (&new->l, head); +list_add_tail (&new->l, head); out:spin_unlock_irqrestore (&info->v2p_lock, flags);
@@ -111,6 +111,7 @@ int scsiback_del_translation_entry(struc found:/* Delete the translation entry specfied */ +scsi_device_put (entry->sdev);list_del (&entry->l);kfree (entry);
@@ -156,6 +157,7 @@ void scsiback_release_translation_entry(spin_lock_irqsave (&info->v2p_lock, flags);list_for_each_entry_safe (entry, tmp, head, l) { +scsi_device_put (entry->sdev);list_del (&entry->l);kfree (entry); }
drivers/xen/scsiback/xenbus.c +78 -38
197 lines not on this page · raw message
drivers/xen/scsifront/scsifront.c +4 -2
@@ -216,6 +216,10 @@ int scsifront_cmd_done(struct vscsifrnt_spin_unlock_irqrestore (&info->io_lock, flags); + +/* Yield point for this unbounded loop. */ +cond_resched (); +return more_to_do; }
@@ -237,8 +241,6 @@ int scsifront_schedule(void *data)if (scsifront_cmd_done (info)) info->waiting_resp =1 ; } - - info->kthread =NULL ;return 0 ; }
drivers/xen/scsifront/xenbus.c +36 -53
174 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 26 lines
diff -r
3132ef07eecf-re235e0bc18abdrivers/xen/scsiback/xenbus.cdrivers/xen/scsiback/xenbus.c +14
-0@@ -113,11 +113,42 @@ struct scsi_device *scsiback_get_scsi_de goto invald_value; } +scsi_host_put (shost); invald_value:return (sdev); }#define VSCSIBACK_OP_ADD_OR_DEL_LUN 1 +#define VSCSIBACK_OP_UPDATEDEV_STATE 2 + +static int scsiback_change_device_state (struct xenbus_device *dev, +char *state_path,enum xenbus_state set_state) +{ +struct xenbus_transaction tr; +int err; + + do { + err = xenbus_transaction_start(&tr); + if (err != 0) { + printk(KERN_ERR "scsiback: transaction start failed\n"); + return err;
drivers/xen/scsiback/xenbus.c struct scsi_device *scsiback_get_scsi_de · line 144
Quoted 10 lines
drivers/xen/scsiback/xenbus.c +10
-0+ } + err =xenbus_printf (tr, dev->nodename, state_path, +"%d" , set_state); +if (err !=0 ) { +printk (KERN_ERR "scsiback: xenbus_printf failed\n" ); +xenbus_transaction_end (tr,1 ); +return err; + } + err =xenbus_transaction_end (tr,0 ); + }while (err == -EAGAIN );
You only do one write in this transaction. That's kind of pointless; you could achieve the same effect more easily and more efficiently by just going
+ err = xenbus_printf(XBT_NIL, dev->nodename, state_path,
+ "%d", set_state);
We have a lot of pointless transactions in other places, so I can understand why you were confused, but we don't really want to introduce any more.
Quoted 31 lines
drivers/xen/scsiback/xenbus.c +15
-4+ +if (err !=0 ) { +printk (KERN_ERR "scsiback: failed to end %s.\n" , __FUNCTION__); +return err; + } +return 0 ; +}static void scsiback_do_lun_hotplug (struct backend_info *be,int op) {@@ -175,16 +201,22 @@ static void scsiback_do_lun_hotplug(struif (device_state == XenbusStateInitialising) { sdev =scsiback_get_scsi_device (&phy);if (!sdev) { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateClosing); + err =scsiback_change_device_state (dev, + state_str, XenbusStateClosing); +if (err) + goto fail; }else { err =scsiback_add_translation_entry (be->info, sdev, &vir);if (!err) { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateInitialised); + err =scsiback_change_device_state (dev, + state_str, XenbusStateInitialised); +if (err) + goto fail;
drivers/xen/scsiback/xenbus.c static void scsiback_do_lun_hotplug(stru · line 222
Quoted 10 lines
drivers/xen/scsiback/xenbus.c +4
-2}else { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateClosing); + err =scsiback_change_device_state (dev, + state_str, XenbusStateClosing); +if (err) + goto fail; } } }
I think you're leaking a reference to sdev when scsiback_add_translation_entry() fails, aren't you? In the success case scsiback_add_translation_entry() transfers it to the translation list, so you don't have to do anything, but in the failure case you do.
Steven.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 3/4 pvSCSI: Fix some part for attach/detach functionality (Re: [PATCH 2/4] pvSCSI : Fix many points of backend/frontend driver)
Hi Steven-san and all,
Attached patch is for following two points you mentioned.
Best regards,
Quoted 96 lines · On Fri, 4 Jul 2008 17:21:59 +0100 Steven Smith <[email protected]> wrote:
Quoted 26 lines
diff -r
3132ef07eecf-re235e0bc18abdrivers/xen/scsiback/xenbus.cdrivers/xen/scsiback/xenbus.c +14
-0@@ -113,11 +113,42 @@ struct scsi_device *scsiback_get_scsi_de goto invald_value; } +scsi_host_put (shost); invald_value:return (sdev); }#define VSCSIBACK_OP_ADD_OR_DEL_LUN 1 +#define VSCSIBACK_OP_UPDATEDEV_STATE 2 + +static int scsiback_change_device_state (struct xenbus_device *dev, +char *state_path,enum xenbus_state set_state) +{ +struct xenbus_transaction tr; +int err; + + do { + err = xenbus_transaction_start(&tr); + if (err != 0) { + printk(KERN_ERR "scsiback: transaction start failed\n"); + return err;drivers/xen/scsiback/xenbus.c struct scsi_device *scsiback_get_scsi_de · line 144
Quoted 10 lines
drivers/xen/scsiback/xenbus.c +10
-0+ } + err =xenbus_printf (tr, dev->nodename, state_path, +"%d" , set_state); +if (err !=0 ) { +printk (KERN_ERR "scsiback: xenbus_printf failed\n" ); +xenbus_transaction_end (tr,1 ); +return err; + } + err =xenbus_transaction_end (tr,0 ); + }while (err == -EAGAIN );You only do one write in this transaction. That's kind of pointless; you could achieve the same effect more easily and more efficiently by just going
(quoted diff) +2
-0+ err = xenbus_printf(XBT_NIL, dev->nodename, state_path, + "%d", set_state);We have a lot of pointless transactions in other places, so I can understand why you were confused, but we don't really want to introduce any more.
Quoted 31 lines
drivers/xen/scsiback/xenbus.c +15
-4+ +if (err !=0 ) { +printk (KERN_ERR "scsiback: failed to end %s.\n" , __FUNCTION__); +return err; + } +return 0 ; +}static void scsiback_do_lun_hotplug (struct backend_info *be,int op) {@@ -175,16 +201,22 @@ static void scsiback_do_lun_hotplug(struif (device_state == XenbusStateInitialising) { sdev =scsiback_get_scsi_device (&phy);if (!sdev) { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateClosing); + err =scsiback_change_device_state (dev, + state_str, XenbusStateClosing); +if (err) + goto fail; }else { err =scsiback_add_translation_entry (be->info, sdev, &vir);if (!err) { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateInitialised); + err =scsiback_change_device_state (dev, + state_str, XenbusStateInitialised); +if (err) + goto fail;drivers/xen/scsiback/xenbus.c static void scsiback_do_lun_hotplug(stru · line 222
Quoted 10 lines
drivers/xen/scsiback/xenbus.c +4
-2}else { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateClosing); + err =scsiback_change_device_state (dev, + state_str, XenbusStateClosing); +if (err) + goto fail; } } }I think you're leaking a reference to sdev when
scsiback_add_translation_entry()fails, aren't you? In the success casescsiback_add_translation_entry()transfers it to the translation list, so you don't have to do anything, but in the failure case you do.
Quoted 1 line
Steven.
-----
Jun Kamada
# HG changeset patch
# User [email protected]
# Date 1215497373 -32400
# Node ID bba146fe2ef8b6c81f6d036e753d8a79cbafdf4b # Parent d73589d6b12bd4df3836c8977985d8d596ab9dda
pvscsi: Fix attach, detach
drivers/xen/scsiback/xenbus.c +30 -67
@@ -104,51 +104,23 @@ struct scsi_device *scsiback_get_scsi_deif (IS_ERR (shost)) {printk (KERN_ERR "scsiback: host%d doesn't exist.\n" , phy->hst); - goto invald_value; +return NULL ; } sdev =scsi_device_lookup (shost, phy->chn, phy->tgt, phy->lun);if (!sdev) {printk (KERN_ERR "scsiback: %d:%d:%d:%d doesn't exist.\n" , phy->hst, phy->chn, phy->tgt, phy->lun); - goto invald_value; +scsi_host_put (shost); +return NULL ; }scsi_host_put (shost); -invald_value:return (sdev); }#define VSCSIBACK_OP_ADD_OR_DEL_LUN 1#define VSCSIBACK_OP_UPDATEDEV_STATE 2 -static int scsiback_change_device_state (struct xenbus_device *dev, -char *state_path,enum xenbus_state set_state) -{ -struct xenbus_transaction tr; -int err; - -do { - err =xenbus_transaction_start (&tr); -if (err !=0 ) { -printk (KERN_ERR "scsiback: transaction start failed\n" ); -return err; - } - err =xenbus_printf (tr, dev->nodename, state_path, -"%d" , set_state); -if (err !=0 ) { -printk (KERN_ERR "scsiback: xenbus_printf failed\n" ); -xenbus_transaction_end (tr,1 ); -return err; - } - err =xenbus_transaction_end (tr,0 ); - }while (err == -EAGAIN ); - -if (err !=0 ) { -printk (KERN_ERR "scsiback: failed to end %s.\n" , __FUNCTION__); -return err; - } -return 0 ; -}static void scsiback_do_lun_hotplug (struct backend_info *be,int op) {
@@ -160,8 +132,6 @@ static void scsiback_do_lun_hotplug(struunsigned int dir_n =0 ;struct xenbus_device *dev = be->dev;struct scsi_device *sdev; -struct xenbus_transaction xbt; - dir =xenbus_directory (XBT_NIL , dev->nodename,"vscsi-devs" , &dir_n);if (IS_ERR (dir))
@@ -181,8 +151,8 @@ static void scsiback_do_lun_hotplug(stru err =xenbus_scanf (XBT_NIL , dev->nodename, str,"%u:%u:%u:%u" , &phy.hst, &phy.chn, &phy.tgt, &phy.lun);if (XENBUS_EXIST_ERR (err)) { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateClosing); +xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateClosed);continue ; }
@@ -191,8 +161,8 @@ static void scsiback_do_lun_hotplug(stru err =xenbus_scanf (XBT_NIL , dev->nodename, str,"%u:%u:%u:%u" , &vir.hst, &vir.chn, &vir.tgt, &vir.lun);if (XENBUS_EXIST_ERR (err)) { -xenbus_printf (xbt, dev->nodename, state_str, -"%d" , XenbusStateClosing); +xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateClosed);continue ; }
@@ -200,36 +170,30 @@ static void scsiback_do_lun_hotplug(strucase VSCSIBACK_OP_ADD_OR_DEL_LUN :if (device_state == XenbusStateInitialising) { sdev =scsiback_get_scsi_device (&phy); -if (!sdev) { - err =scsiback_change_device_state (dev, - state_str, XenbusStateClosing); -if (err) - goto fail; - }else { +if (!sdev) +xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateClosed); +else { err =scsiback_add_translation_entry (be->info, sdev, &vir);if (!err) { - err =scsiback_change_device_state (dev, - state_str, XenbusStateInitialised); -if (err) - goto fail; +if (xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateInitialised)) { +printk (KERN_ERR "scsiback: xenbus_printf error %s\n" , state_str); +scsiback_del_translation_entry (be->info, &vir); + } }else { - err =scsiback_change_device_state (dev, - state_str, XenbusStateClosing); -if (err) - goto fail; +scsi_device_put (sdev); +xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateClosed); } } }if (device_state == XenbusStateClosing) { - err =scsiback_del_translation_entry (be->info, &vir); -if (err) - goto fail; -else { - err =scsiback_change_device_state (dev, - state_str, XenbusStateClosed); -if (err) - goto fail; +if (!scsiback_del_translation_entry (be->info, &vir)) { +if (xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateClosed)) +printk (KERN_ERR "scsiback: xenbus_printf error %s\n" , state_str); } }break ;
@@ -237,10 +201,13 @@ static void scsiback_do_lun_hotplug(strucase VSCSIBACK_OP_UPDATEDEV_STATE :if (device_state == XenbusStateInitialised) {/* modify vscsi-devs/dev-x/state */ - err =scsiback_change_device_state (dev, - state_str, XenbusStateConnected); -if (err) - goto fail; +if (xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateConnected)) { +printk (KERN_ERR "scsiback: xenbus_printf error %s\n" , state_str); +scsiback_del_translation_entry (be->info, &vir); +xenbus_printf (XBT_NIL , dev->nodename, state_str, +"%d" , XenbusStateClosed); + } }break ;/*When it is necessary, processing is added here.*/
@@ -251,10 +218,6 @@ static void scsiback_do_lun_hotplug(strukfree (dir);return ; -fail : -kfree (dir); -xenbus_dev_fatal (dev, err,"read or write %s " , str); -return ; }
drivers/xen/scsifront/xenbus.c +5 -11
@@ -100,13 +100,13 @@ static int scsifront_alloc_ring(struct vif (err <=0 ) {xenbus_dev_fatal (dev, err,"bind_listening_port_to_irqhandler" ); - goto fail; + goto free_sring; } info->irq = err;return 0 ; -fail: -/* free resource */ + +/* free resource */ free_sring:scsifront_free (info);
@@ -298,14 +298,14 @@ static void scsifront_do_lun_hotplug(str err =xenbus_scanf (XBT_NIL , dev->otherend, str,"%u" , &device_state);if (XENBUS_EXIST_ERR (err)) - goto fail; +continue ;/* virtual SCSI device */ snprintf (str,sizeof (str),"vscsi-devs/%s/v-dev" , dir[i]); err =xenbus_scanf (XBT_NIL , dev->otherend, str,"%u:%u:%u:%u" , &hst, &chn, &tgt, &lun);if (XENBUS_EXIST_ERR (err)) - goto fail; +continue ;/* front device state path */ snprintf (state_str,sizeof (state_str),"vscsi-devs/%s/state" , dir[i]);
@@ -338,17 +338,11 @@ static void scsifront_do_lun_hotplug(str }break ;default : - goto fail;break ; } }kfree (dir); -return ; - -fail: -kfree (dir); -xenbus_dev_fatal (dev, err,"read or write %s " , str);return ; }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 3/4] pvSCSI: Fix some part for attach/detach functionality (Re: [PATCH 2/4] pvSCSI : Fix many points of backend/frontend driver)
Quoted 1 line
Attached patch is for following two points you mentioned.
That looks much better, thanks.
Steven.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel