From patchwork Tue Apr 15 19:47:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3995151 X-Patchwork-Delegate: dave@jikos.cz Return-Path: X-Original-To: patchwork-linux-btrfs@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 EF7329F336 for ; Tue, 15 Apr 2014 18:47:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 206F22018E for ; Tue, 15 Apr 2014 18:47:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C9AE2026C for ; Tue, 15 Apr 2014 18:47:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755072AbaDOSra (ORCPT ); Tue, 15 Apr 2014 14:47:30 -0400 Received: from mail-we0-f170.google.com ([74.125.82.170]:57256 "EHLO mail-we0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753222AbaDOSr0 (ORCPT ); Tue, 15 Apr 2014 14:47:26 -0400 Received: by mail-we0-f170.google.com with SMTP id w61so10014462wes.15 for ; Tue, 15 Apr 2014 11:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=PW/ackktpXvK5NZULt7qyr8xFGe9NoR18lUZTPMWXIM=; b=V7ppfRSmPFrQa0c4TDbRc1cNZiVuVewiQM8QZJnIL8w6+NqZtHBkBsz1K9nkZMx7PX lrH9kOx0PHxdgViHC/BWf4N45vWsolL/rE2I82duAbuZaRTfpOihv/X2lE46Hs5vO3Pe WLIWnoQhUL7T5DHd+Z9HXRgFBkAqhFsxJPeGN/aBc+iWQvU84T4cllqwQTSpYutk30L7 SNgvZl/jypwsIVNpnIh34RVgO9B7Y+D5eXhLNIDUiv+1HEC3ZdPe7uEa1iqS3JAGQR2z ZwNGGXvwKNmgQrYCTDA7Qe6PnfHeT0YPn1bmuTT6ETa0hWwlfKFSTypKU7PlB5RRT/6V hyqg== X-Received: by 10.180.92.34 with SMTP id cj2mr12413117wib.15.1397587645858; Tue, 15 Apr 2014 11:47:25 -0700 (PDT) Received: from debian-vm3.lan (bl10-141-238.dsl.telepac.pt. [85.243.141.238]) by mx.google.com with ESMTPSA id h1sm30837424wjy.7.2014.04.15.11.47.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Apr 2014 11:47:25 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs-progs: allow compression property gets for read-only subvolumes Date: Tue, 15 Apr 2014 20:47:27 +0100 Message-Id: <1397591247-25376-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Because the function open_file_or_dir() always opened the input file in read/write mode (O_RDWR), we were not able to due a compression property get against a file living in a read-only subvolume/snapshot. Fix this by opening the file with O_RDONLY mode if we're doing a property get. Signed-off-by: Filipe David Borba Manana Reviewed-by: Liu Bo --- props.c | 3 ++- utils.c | 9 +++++++-- utils.h | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/props.c b/props.c index 4d0aeea..bd74975 100644 --- a/props.c +++ b/props.c @@ -119,8 +119,9 @@ static int prop_compression(enum prop_object_type type, DIR *dirstream = NULL; char *buf = NULL; char *xattr_name = NULL; + int open_flags = value ? O_RDWR : O_RDONLY; - fd = open_file_or_dir(object, &dirstream); + fd = open_file_or_dir3(object, &dirstream, open_flags); if (fd == -1) { ret = -errno; fprintf(stderr, "ERROR: open %s failed. %s\n", diff --git a/utils.c b/utils.c index 0bfb9d9..458ba54 100644 --- a/utils.c +++ b/utils.c @@ -1625,7 +1625,7 @@ u64 parse_size(char *s) return strtoull(s, NULL, 10) * mult; } -int open_file_or_dir(const char *fname, DIR **dirstream) +int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags) { int ret; struct stat st; @@ -1641,7 +1641,7 @@ int open_file_or_dir(const char *fname, DIR **dirstream) return -1; fd = dirfd(*dirstream); } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { - fd = open(fname, O_RDWR); + fd = open(fname, open_flags); } else { /* * we set this on purpose, in case the caller output @@ -1658,6 +1658,11 @@ int open_file_or_dir(const char *fname, DIR **dirstream) return fd; } +int open_file_or_dir(const char *fname, DIR **dirstream) +{ + return open_file_or_dir3(fname, dirstream, O_RDWR); +} + void close_file_or_dir(int fd, DIR *dirstream) { if (dirstream) diff --git a/utils.h b/utils.h index 06ec938..fc581ca 100644 --- a/utils.h +++ b/utils.h @@ -73,6 +73,7 @@ int btrfs_scan_block_devices(int run_ioctl); u64 parse_size(char *s); u64 arg_strtou64(const char *str); int open_file_or_dir(const char *fname, DIR **dirstream); +int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags); void close_file_or_dir(int fd, DIR *dirstream); int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, struct btrfs_ioctl_dev_info_args **di_ret);