From: Pascal VITOUX <vitoux.pascal@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Pascal VITOUX <vitoux.pascal@gmail.com>
Subject: [PATCH] btrfs-progs: skip non-regular files while defragmenting
Date: Thu, 9 Jan 2014 23:47:14 +0100 [thread overview]
Message-ID: <1389307634-8226-1-git-send-email-vitoux.pascal@gmail.com> (raw)
Skip non-regular files to avoid ioctl errors while defragmenting.
They are silently ignored in recursive mode but reported as errors when
used as command-line arguments.
Signed-off-by: Pascal VITOUX <vitoux.pascal@gmail.com>
---
cmds-filesystem.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 1c1926b..54fba10 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -646,7 +646,7 @@ static int defrag_callback(const char *fpath, const struct stat *sb,
int e = 0;
int fd = 0;
- if (typeflag == FTW_F) {
+ if ((typeflag == FTW_F) && S_ISREG(sb->st_mode)) {
if (defrag_global_verbose)
printf("%s\n", fpath);
fd = open(fpath, O_RDWR);
@@ -748,6 +748,7 @@ static int cmd_defrag(int argc, char **argv)
defrag_global_range.flags |= BTRFS_DEFRAG_RANGE_START_IO;
for (i = optind; i < argc; i++) {
+ struct stat st;
dirstream = NULL;
fd = open_file_or_dir(argv[i], &dirstream);
if (fd < 0) {
@@ -757,16 +758,21 @@ static int cmd_defrag(int argc, char **argv)
close_file_or_dir(fd, dirstream);
continue;
}
+ if (fstat(fd, &st)) {
+ fprintf(stderr, "ERROR: failed to stat %s - %s\n",
+ argv[i], strerror(errno));
+ defrag_global_errors++;
+ close_file_or_dir(fd, dirstream);
+ continue;
+ }
+ if (!(S_ISDIR(st.st_mode) || S_ISREG(st.st_mode))) {
+ fprintf(stderr, "ERROR: %s is not a directory or a regular "
+ "file.\n", argv[i]);
+ defrag_global_errors++;
+ close_file_or_dir(fd, dirstream);
+ continue;
+ }
if (recursive) {
- struct stat st;
-
- if (fstat(fd, &st)) {
- fprintf(stderr, "ERROR: failed to stat %s - %s\n",
- argv[i], strerror(errno));
- defrag_global_errors++;
- close_file_or_dir(fd, dirstream);
- continue;
- }
if (S_ISDIR(st.st_mode)) {
ret = nftw(argv[i], defrag_callback, 10,
FTW_MOUNT | FTW_PHYS);
--
1.8.5.2
next reply other threads:[~2014-01-09 22:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-09 22:47 Pascal VITOUX [this message]
2014-01-10 14:13 ` [PATCH] btrfs-progs: skip non-regular files while defragmenting 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=1389307634-8226-1-git-send-email-vitoux.pascal@gmail.com \
--to=vitoux.pascal@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.