slyfox 14/03/10 19:34:29 Added: btrfs-progs-3.12-defrag-sockets.patch Log: Fix recursive defrag failures on non-files (bug #503514 by Antoine Lemoine). (Portage version: 2.2.8_p62/cvs/Linux x86_64, signed Manifest commit with key 611FF3AA)
Revision Changes Path 1.1 sys-fs/btrfs-progs/files/btrfs-progs-3.12-defrag-sockets.patch file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-fs/btrfs-progs/files/btrfs-progs-3.12-defrag-sockets.patch?rev=1.1&view=markup plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-fs/btrfs-progs/files/btrfs-progs-3.12-defrag-sockets.patch?rev=1.1&content-type=text/plain Index: btrfs-progs-3.12-defrag-sockets.patch =================================================================== From: Pascal VITOUX <[email protected]> To: [email protected] Cc: Pascal VITOUX <[email protected]> Subject: [PATCH] btrfs-progs: skip non-regular files while defragmenting Date: Thu, 9 Jan 2014 23:47:14 +0100 Message-Id: <[email protected]> X-Mailer: git-send-email 1.8.5.2 Sender: [email protected] Precedence: bulk List-ID: <linux-btrfs.vger.kernel.org> X-Mailing-List: [email protected] 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 <[email protected]> Gentoo-bug: https://bugs.gentoo.org/503514 Reported-by: Antoine Lemoine --- 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
