diff mbox

qemu-nbd: return EROFS for discard on a read-only export

Message ID 1431012374-14113-1-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini May 7, 2015, 3:26 p.m. UTC
This is consistent with the handling of writes.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 nbd.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Max Reitz May 8, 2015, 12:43 p.m. UTC | #1
On 07.05.2015 17:26, Paolo Bonzini wrote:
> This is consistent with the handling of writes.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   nbd.c | 6 ++++++
>   1 file changed, 6 insertions(+)

Reviewed-by: Max Reitz <mreitz@redhat.com>
diff mbox

Patch

diff --git a/nbd.c b/nbd.c
index cb1b9bb..eea8c51 100644
--- a/nbd.c
+++ b/nbd.c
@@ -1325,6 +1325,12 @@  static void nbd_trip(void *opaque)
         break;
     case NBD_CMD_TRIM:
         TRACE("Request type is TRIM");
+        if (exp->nbdflags & NBD_FLAG_READ_ONLY) {
+            TRACE("Server is read-only, return error");
+            reply.error = EROFS;
+            goto error_reply;
+        }
+
         ret = blk_co_discard(exp->blk, (request.from + exp->dev_offset)
                                        / BDRV_SECTOR_SIZE,
                              request.len / BDRV_SECTOR_SIZE);