From patchwork Thu May 7 15:26:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 469716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9A5EE140281 for ; Fri, 8 May 2015 01:26:43 +1000 (AEST) Received: from localhost ([::1]:51743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqNhB-0004ly-3z for incoming@patchwork.ozlabs.org; Thu, 07 May 2015 11:26:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqNgr-0004Ht-KL for qemu-devel@nongnu.org; Thu, 07 May 2015 11:26:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqNgo-0002HE-Ep for qemu-devel@nongnu.org; Thu, 07 May 2015 11:26:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqNgo-0002H9-AV for qemu-devel@nongnu.org; Thu, 07 May 2015 11:26:18 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id E8E828EA57 for ; Thu, 7 May 2015 15:26:17 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-76.ams2.redhat.com [10.36.112.76]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t47FQFlT006231; Thu, 7 May 2015 11:26:16 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 May 2015 17:26:13 +0200 Message-Id: <1431012374-14113-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, mreitz@redhat.com Subject: [Qemu-devel] [PATCH] qemu-nbd: return EROFS for discard on a read-only export X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is consistent with the handling of writes. Signed-off-by: Paolo Bonzini Reviewed-by: Max Reitz --- 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);