From patchwork Sun Mar 28 17:07:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryota OZAKI X-Patchwork-Id: 48784 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DA0B6B7C33 for ; Mon, 29 Mar 2010 04:22:18 +1100 (EST) Received: from localhost ([127.0.0.1]:42763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nvw2T-00046T-GN for incoming@patchwork.ozlabs.org; Sun, 28 Mar 2010 13:12:41 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvvzP-0003QA-FT for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:31 -0400 Received: from [140.186.70.92] (port=39856 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvvzN-0003Pb-Tm for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvvzM-0007em-Io for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:29 -0400 Received: from mail-iw0-f171.google.com ([209.85.223.171]:48771) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvvzM-0007eM-Fd for qemu-devel@nongnu.org; Sun, 28 Mar 2010 13:09:28 -0400 Received: by mail-iw0-f171.google.com with SMTP id 1so6816858iwn.27 for ; Sun, 28 Mar 2010 10:09:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=mtPQLMXIAUz30/BXIh9tqNbMEVrkv77TBHd/Sevls8k=; b=dTDcmAdhhZ5Q2HRvCVuWBTUlJXfyRO9KYdYZoC4zutfnyTvWzBuCtjfUO9Ame4F6IH naqGfedbhXjzbwNSxIEyPqd90F9wbvoEAlVfK9PVHtpQzZpfSW5AZPcq2OSU40tT6dCH JcqKXdPqWvjmwOAKAK+SxKOzlBeGjAOn4V33A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=Wk5V9WyK+WOhFFodohAPMbEs2uO9HOcitxmltH1Ke2DsbLcCVf3+k+VcM1b6vxR6R1 dQ7vKlQq5qxbJ0A9R0KJSmWyGuHdRM8nhD69iPA/hVdw/XpqSl3p/QXeXZIgxnw2KKyH P8VR34vBZReSKNLFbMjEJRzzlg8hcvoXgyhWc= Received: by 10.231.161.132 with SMTP id r4mr1949484ibx.48.1269796168336; Sun, 28 Mar 2010 10:09:28 -0700 (PDT) Received: from localhost.localdomain (host105.nvlab.org [122.1.115.105]) by mx.google.com with ESMTPS id cm22sm2831437ibb.11.2010.03.28.10.09.26 (version=SSLv3 cipher=RC4-MD5); Sun, 28 Mar 2010 10:09:27 -0700 (PDT) From: Ryota Ozaki To: qemu-devel@nongnu.org Date: Mon, 29 Mar 2010 02:07:11 +0900 Message-Id: <1269796032-9166-2-git-send-email-ozaki.ryota@gmail.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1269796032-9166-1-git-send-email-ozaki.ryota@gmail.com> References: <1269796032-9166-1-git-send-email-ozaki.ryota@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 2/3] qemu-nbd: Extend read-only option to nbd device file X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch allows to operate on nbd device file without write permission for the file if read-only option is specified. Signed-off-by: Ryota Ozaki --- qemu-nbd.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 00b8896..7ef409f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -162,7 +162,7 @@ static int find_partition(BlockDriverState *bs, int partition, return -1; } -static void show_parts(const char *device) +static void show_parts(const char *device, bool readonly) { if (fork() == 0) { int nbd; @@ -172,7 +172,7 @@ static void show_parts(const char *device) * but remember to load the module with max_part != 0 : * modprobe nbd max_part=63 */ - nbd = open(device, O_RDWR); + nbd = open(device, readonly ? O_RDONLY : O_RDWR); if (nbd != -1) { close(nbd); } @@ -322,7 +322,7 @@ int main(int argc, char **argv) } if (disconnect) { - fd = open(argv[optind], O_RDWR); + fd = open(argv[optind], readonly ? O_RDONLY : O_RDWR); if (fd == -1) { errx(EXIT_FAILURE, "Cannot open %s", argv[optind]); } @@ -392,7 +392,7 @@ int main(int argc, char **argv) } } while (sock == -1); - fd = open(device, O_RDWR); + fd = open(device, readonly ? O_RDONLY : O_RDWR); if (fd == -1) { ret = 1; goto out; @@ -415,7 +415,7 @@ int main(int argc, char **argv) /* update partition table */ - show_parts(device); + show_parts(device, readonly); nbd_client(fd, sock); close(fd);