qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] iscsi: Handle write protected case in reopen
@ 2015-02-25  4:40 Fam Zheng
  2015-02-27 14:20 ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Fam Zheng @ 2015-02-25  4:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Paolo Bonzini, Peter Lieven, Stefan Hajnoczi,
	Ronnie Sahlberg

Save the write protected flag and check before reopen.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 block/iscsi.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 12ddbfb..00041bf 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -65,6 +65,7 @@ typedef struct IscsiLun {
     unsigned long *allocationmap;
     int cluster_sectors;
     bool use_16_for_rw;
+    bool write_proteced;
 } IscsiLun;
 
 typedef struct IscsiTask {
@@ -1268,10 +1269,6 @@ out:
 /*
  * We support iscsi url's on the form
  * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
- *
- * Note: flags are currently not used by iscsi_open.  If this function
- * is changed such that flags are used, please examine iscsi_reopen_prepare()
- * to see if needs to be changed as well.
  */
 static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
                       Error **errp)
@@ -1385,9 +1382,10 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
     scsi_free_scsi_task(task);
     task = NULL;
 
+    iscsilun->write_proteced = iscsi_is_write_protected(iscsilun);
     /* Check the write protect flag of the LUN if we want to write */
     if (iscsilun->type == TYPE_DISK && (flags & BDRV_O_RDWR) &&
-        iscsi_is_write_protected(iscsilun)) {
+        iscsilun->write_proteced) {
         error_setg(errp, "Cannot open a write protected LUN as read-write");
         ret = -EACCES;
         goto out;
@@ -1541,13 +1539,17 @@ static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
         sector_limits_lun2qemu(iscsilun->bl.opt_xfer_len, iscsilun);
 }
 
-/* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in
- * prepare.  Note that this will not re-establish a connection with an iSCSI
- * target - it is effectively a NOP.  */
+/* Note that this will not re-establish a connection with an iSCSI target - it
+ * is effectively a NOP.  */
 static int iscsi_reopen_prepare(BDRVReopenState *state,
                                 BlockReopenQueue *queue, Error **errp)
 {
-    /* NOP */
+    IscsiLun *iscsilun = state->bs->opaque;
+
+    if (state->flags & BDRV_O_RDWR && iscsilun->write_proteced) {
+        error_setg(errp, "Cannot open a write protected LUN as read-write");
+        return -EACCES;
+    }
     return 0;
 }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] iscsi: Handle write protected case in reopen
  2015-02-25  4:40 [Qemu-devel] [PATCH] iscsi: Handle write protected case in reopen Fam Zheng
@ 2015-02-27 14:20 ` Paolo Bonzini
  2015-02-27 17:41   ` Peter Lieven
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2015-02-27 14:20 UTC (permalink / raw)
  To: Fam Zheng, qemu-devel
  Cc: Kevin Wolf, Peter Lieven, Stefan Hajnoczi, Ronnie Sahlberg



On 25/02/2015 05:40, Fam Zheng wrote:
> Save the write protected flag and check before reopen.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  block/iscsi.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 12ddbfb..00041bf 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -65,6 +65,7 @@ typedef struct IscsiLun {
>      unsigned long *allocationmap;
>      int cluster_sectors;
>      bool use_16_for_rw;
> +    bool write_proteced;

Corrected to "write_protecTed" and applied.

Paolo

>  } IscsiLun;
>  
>  typedef struct IscsiTask {
> @@ -1268,10 +1269,6 @@ out:
>  /*
>   * We support iscsi url's on the form
>   * iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
> - *
> - * Note: flags are currently not used by iscsi_open.  If this function
> - * is changed such that flags are used, please examine iscsi_reopen_prepare()
> - * to see if needs to be changed as well.
>   */
>  static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
>                        Error **errp)
> @@ -1385,9 +1382,10 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
>      scsi_free_scsi_task(task);
>      task = NULL;
>  
> +    iscsilun->write_proteced = iscsi_is_write_protected(iscsilun);
>      /* Check the write protect flag of the LUN if we want to write */
>      if (iscsilun->type == TYPE_DISK && (flags & BDRV_O_RDWR) &&
> -        iscsi_is_write_protected(iscsilun)) {
> +        iscsilun->write_proteced) {
>          error_setg(errp, "Cannot open a write protected LUN as read-write");
>          ret = -EACCES;
>          goto out;
> @@ -1541,13 +1539,17 @@ static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
>          sector_limits_lun2qemu(iscsilun->bl.opt_xfer_len, iscsilun);
>  }
>  
> -/* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in
> - * prepare.  Note that this will not re-establish a connection with an iSCSI
> - * target - it is effectively a NOP.  */
> +/* Note that this will not re-establish a connection with an iSCSI target - it
> + * is effectively a NOP.  */
>  static int iscsi_reopen_prepare(BDRVReopenState *state,
>                                  BlockReopenQueue *queue, Error **errp)
>  {
> -    /* NOP */
> +    IscsiLun *iscsilun = state->bs->opaque;
> +
> +    if (state->flags & BDRV_O_RDWR && iscsilun->write_proteced) {
> +        error_setg(errp, "Cannot open a write protected LUN as read-write");
> +        return -EACCES;
> +    }
>      return 0;
>  }
>  
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] iscsi: Handle write protected case in reopen
  2015-02-27 14:20 ` Paolo Bonzini
@ 2015-02-27 17:41   ` Peter Lieven
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Lieven @ 2015-02-27 17:41 UTC (permalink / raw)
  To: Paolo Bonzini, Fam Zheng, qemu-devel
  Cc: Kevin Wolf, Stefan Hajnoczi, Ronnie Sahlberg

Am 27.02.2015 um 15:20 schrieb Paolo Bonzini:
>
> On 25/02/2015 05:40, Fam Zheng wrote:
>> Save the write protected flag and check before reopen.
>>
>> Signed-off-by: Fam Zheng <famz@redhat.com>
>> ---
>>  block/iscsi.c | 20 +++++++++++---------
>>  1 file changed, 11 insertions(+), 9 deletions(-)
>>
>> diff --git a/block/iscsi.c b/block/iscsi.c
>> index 12ddbfb..00041bf 100644
>> --- a/block/iscsi.c
>> +++ b/block/iscsi.c
>> @@ -65,6 +65,7 @@ typedef struct IscsiLun {
>>      unsigned long *allocationmap;
>>      int cluster_sectors;
>>      bool use_16_for_rw;
>> +    bool write_proteced;
> Corrected to "write_protecTed" and applied.

Is this a bug fix? qemu-stable?

Peter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-27 17:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-25  4:40 [Qemu-devel] [PATCH] iscsi: Handle write protected case in reopen Fam Zheng
2015-02-27 14:20 ` Paolo Bonzini
2015-02-27 17:41   ` Peter Lieven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).