From patchwork Wed Dec 11 06:43:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 3322541 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2BB6B9F37C for ; Wed, 11 Dec 2013 06:46:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5987720749 for ; Wed, 11 Dec 2013 06:46:52 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id 3774D20396 for ; Wed, 11 Dec 2013 06:46:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBB6i3m0017745; Wed, 11 Dec 2013 01:44:03 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBB6hZAa021185 for ; Wed, 11 Dec 2013 01:43:35 -0500 Received: from dhcp80-209.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBB6hYid005062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Dec 2013 01:43:35 -0500 Received: from dhcp80-209.msp.redhat.com (localhost [127.0.0.1]) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7) with ESMTP id rBB6hXDL001376; Wed, 11 Dec 2013 00:43:34 -0600 Received: (from bmarzins@localhost) by dhcp80-209.msp.redhat.com (8.14.7/8.14.7/Submit) id rBB6hWHg001375; Wed, 11 Dec 2013 00:43:32 -0600 From: Benjamin Marzinski To: device-mapper development Date: Wed, 11 Dec 2013 00:43:04 -0600 Message-Id: <1386744190-1295-11-git-send-email-bmarzins@redhat.com> In-Reply-To: <1386744190-1295-1-git-send-email-bmarzins@redhat.com> References: <1386744190-1295-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: Till Maas , Christophe Varoqui Subject: [dm-devel] [PATCH 10/16] kpartx: Make kpartx able to create read-only loop devices X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This just passes the read-only value into set_loop, and falls back to read-only mapping on EACCESS to handle immutable files. Signed-off-by: Till Maas Signed-off-by: Benjamin Marzinski --- kpartx/kpartx.c | 3 +-- kpartx/lopart.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c index 1369542..9a9a5eb 100644 --- a/kpartx/kpartx.c +++ b/kpartx/kpartx.c @@ -205,7 +205,6 @@ main(int argc, char **argv){ char * delim = NULL; char *uuid = NULL; char *mapname = NULL; - int loopro = 0; int hotplug = 0; int loopcreated = 0; struct stat buf; @@ -316,7 +315,7 @@ main(int argc, char **argv){ if (!loopdev) { loopdev = find_unused_loop_device(); - if (set_loop(loopdev, device, 0, &loopro)) { + if (set_loop(loopdev, device, 0, &ro)) { fprintf(stderr, "can't set up loop\n"); exit (1); } diff --git a/kpartx/lopart.c b/kpartx/lopart.c index 79a7593..9082ca8 100644 --- a/kpartx/lopart.c +++ b/kpartx/lopart.c @@ -230,7 +230,7 @@ set_loop (const char *device, const char *file, int offset, int *loopro) if ((ffd = open (file, mode)) < 0) { - if (!*loopro && errno == EROFS) + if (!*loopro && (errno == EROFS || errno == EACCES)) ffd = open (file, mode = O_RDONLY); if (ffd < 0) {