From e68e74dc4f5fa1feed6b87c3d3a8a21da81d564f Mon Sep 17 00:00:00 2001 From: Thomas Horsten Date: Wed, 16 Sep 2009 10:49:21 +0100 Subject: [PATCH] Add mutex to bsg SG_IO ioctl --- master/bsg-add-global-sgio-mutex.patch | 44 ++++++++++++++++++++++++++ master/series | 1 + 2 files changed, 45 insertions(+) create mode 100644 master/bsg-add-global-sgio-mutex.patch diff --git a/master/bsg-add-global-sgio-mutex.patch b/master/bsg-add-global-sgio-mutex.patch new file mode 100644 index 0000000..14c6cec --- /dev/null +++ b/master/bsg-add-global-sgio-mutex.patch @@ -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; diff --git a/master/series b/master/series index ba31455..09f7295 100644 --- a/master/series +++ b/master/series @@ -314,3 +314,4 @@ blktap2-pause-unpause blktap2-smp-map-unmap bridge-carrier-follows-prio0.patch v2v-core +bsg-add-global-sgio-mutex.patch -- 2.39.5