]> xenbits.xen.org Git - xenclient/linux-2.6.27-pq.git/commitdiff
Add mutex to bsg SG_IO ioctl
authorThomas Horsten <thomas.horsten@citrix.com>
Wed, 16 Sep 2009 09:49:21 +0000 (10:49 +0100)
committerThomas Horsten <thomas.horsten@citrix.com>
Wed, 16 Sep 2009 09:49:21 +0000 (10:49 +0100)
master/bsg-add-global-sgio-mutex.patch [new file with mode: 0644]
master/series

diff --git a/master/bsg-add-global-sgio-mutex.patch b/master/bsg-add-global-sgio-mutex.patch
new file mode 100644 (file)
index 0000000..14c6cec
--- /dev/null
@@ -0,0 +1,44 @@
+diff --git a/block/bsg.c b/block/bsg.c
+index 9cfbea8..6f9644c 100644
+--- a/block/bsg.c
++++ b/block/bsg.c
+@@ -874,6 +874,12 @@ static unsigned int bsg_poll(struct file *file, poll_table *wait)
+       return mask;
+ }
++/* This is an ugly hack for XC to ensure exclusive access to the
++ * CD-ROM between multiple VM's. This should be handled by the caller
++ * but this will suffice for now since no-one else in dom0 will use
++ * the SG_IO interface */
++static DEFINE_MUTEX(sg_io_mutex);
++
+ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+ {
+       struct bsg_device *bd = file->private_data;
+@@ -922,16 +928,24 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+               if (copy_from_user(&hdr, uarg, sizeof(hdr)))
+                       return -EFAULT;
+-
++              
++              /* XC-Hack: */
++              /* Acquire mutex to ensure exclusive access between VMs*/
++              //if (mutex_is_locked(&sg_io_mutex))
++              //    printk(KERN_NOTICE "bsg: sg_io_mutex already locked (pid=%d)\n", current->pid);
++              mutex_lock(&sg_io_mutex);
+               rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE);
+-              if (IS_ERR(rq))
++              if (IS_ERR(rq)) {
++                      mutex_unlock(&sg_io_mutex);
+                       return PTR_ERR(rq);
++              }
+               bio = rq->bio;
+               if (rq->next_rq)
+                       bidi_bio = rq->next_rq->bio;
+               blk_execute_rq(bd->queue, NULL, rq, 0);
+               ret = blk_complete_sgv4_hdr_rq(rq, &hdr, bio, bidi_bio);
++              mutex_unlock(&sg_io_mutex);
+               if (copy_to_user(uarg, &hdr, sizeof(hdr)))
+                       return -EFAULT;
index ba314553b22679542f725cfc28e85f7f0dcc6779..09f7295485df1ffef5a78b636bedc062aa0c89b4 100644 (file)
@@ -314,3 +314,4 @@ blktap2-pause-unpause
 blktap2-smp-map-unmap
 bridge-carrier-follows-prio0.patch
 v2v-core
+bsg-add-global-sgio-mutex.patch