This is consistent with the handling of writes.
Signed-off-by: Paolo Bonzini <[email protected]>
---
nbd.c | 6 ++++++
1 file changed, 6 insertions(+)
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);
--
2.3.5