From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: [PATCH 6/9] btrfs-progs: mkfs: Fix regression preventing --rootdir to create file
Date: Wed, 29 Nov 2017 17:16:01 +0800 [thread overview]
Message-ID: <20171129091604.2194-7-wqu@suse.com> (raw)
In-Reply-To: <20171129091604.2194-1-wqu@suse.com>
Commit 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
will try to check the file state before creating fs on it.
The check is mostly fine for normal mkfs case, while for --rootdir
option, it's allowed to create new file if destination file doesn't
exist.
Fix it by allowing non-existing file if --rootdir is specified.
Fixes: 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
mkfs/main.c | 6 ++++--
utils.c | 15 +++++++++++++++
utils.h | 1 +
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 64cf03289188..a34b73bfb845 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -733,7 +733,7 @@ int main(int argc, char **argv)
u32 stripesize = 4096;
int zero_end = 1;
int fd = -1;
- int ret;
+ int ret = 0;
int close_ret;
int i;
int mixed = 0;
@@ -913,7 +913,9 @@ int main(int argc, char **argv)
while (dev_cnt-- > 0) {
file = argv[optind++];
- if (is_block_device(file) == 1)
+ if (source_dir_set && is_path_exist(file) == 0)
+ ret = 0;
+ else if (is_block_device(file) == 1)
ret = test_dev_for_mkfs(file, force_overwrite);
else
ret = test_status_for_mkfs(file, force_overwrite);
diff --git a/utils.c b/utils.c
index 524f463d3140..22c137514592 100644
--- a/utils.c
+++ b/utils.c
@@ -456,6 +456,21 @@ static int is_reg_file(const char *path)
return S_ISREG(statbuf.st_mode);
}
+int is_path_exist(const char *path)
+{
+ struct stat statbuf;
+ int ret;
+
+ ret = stat(path, &statbuf);
+ if (ret < 0) {
+ if (errno == ENOENT)
+ return 0;
+ else
+ return -errno;
+ }
+ return 1;
+}
+
/*
* This function checks if the given input parameter is
* an uuid or a path
diff --git a/utils.h b/utils.h
index a82d46f6d7cc..860c25d3cdba 100644
--- a/utils.h
+++ b/utils.h
@@ -122,6 +122,7 @@ int set_label(const char *btrfs_dev, const char *label);
char *__strncpy_null(char *dest, const char *src, size_t n);
int is_block_device(const char *file);
int is_mount_point(const char *file);
+int is_path_exist(const char *file);
int check_arg_type(const char *input);
int open_path_or_dev_mnt(const char *path, DIR **dirstream, int verbose);
int btrfs_open(const char *path, DIR **dirstream, int verbose, int dir_only);
--
2.15.0
next prev parent reply other threads:[~2017-11-29 9:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 9:15 [PATCH 0/9] Remaining part of mkfs --rootdir rework Qu Wenruo
2017-11-29 9:15 ` [PATCH 1/9] btrfs-progs: mkfs: Cleanup temporary chunks before filling rootdir Qu Wenruo
2017-11-29 9:15 ` [PATCH 2/9] btrfs-progs: mkfs: Don't use custom chunk allocator for rootdir Qu Wenruo
2017-11-29 9:15 ` [PATCH 3/9] btrfs-progs: mkfs/rootdir: Use over-reserve method to make size estimate easier Qu Wenruo
2017-11-29 9:15 ` [PATCH 4/9] btrfs-progs: mkfs/rootdir: Shrink fs for rootdir option Qu Wenruo
2017-11-29 9:16 ` [PATCH 5/9] btrfs-progs: mkfs: Separate shrink from rootdir Qu Wenruo
2017-11-29 9:16 ` Qu Wenruo [this message]
2017-11-30 5:16 ` [PATCH 6/9] btrfs-progs: mkfs: Fix regression preventing --rootdir to create file Misono, Tomohiro
2017-11-29 9:16 ` [PATCH 7/9] btrfs-progs: tests/mkfs: Introduce test case to check if mkfs rootdir can create new file Qu Wenruo
2017-11-29 9:16 ` [PATCH 8/9] btrfs-progs: mkfs: Use the whole file or block device to mkfs for rootdir Qu Wenruo
2017-11-29 9:16 ` [PATCH 9/9] btrfs-progs: tests/mkfs: Introduce test case to verify if mkfs.btrfs rootdir shrink behaves correctly Qu Wenruo
2017-12-07 19:06 ` [PATCH 0/9] Remaining part of mkfs --rootdir rework David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171129091604.2194-7-wqu@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).