* [PATCH v2] duperemove: test presence of dedupe ioctl
@ 2016-12-16 1:21 Darrick J. Wong
2016-12-16 7:53 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2016-12-16 1:21 UTC (permalink / raw)
To: mfasheh; +Cc: xfs, Christoph Hellwig, linux-btrfs
Since a zero-length dedupe operation is guaranteed to succeed, use that
to test whether or not this filesystem supports dedupe.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: Don't declare a new type; just declare the struct on the stack.
---
file_scan.c | 45 +++++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)
diff --git a/file_scan.c b/file_scan.c
index 617f166..2708bfe 100644
--- a/file_scan.c
+++ b/file_scan.c
@@ -45,11 +45,7 @@
#include "file_scan.h"
#include "dbfile.h"
#include "util.h"
-
-/* This is not in linux/magic.h */
-#ifndef XFS_SB_MAGIC
-#define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
-#endif
+#include "btrfs-ioctl.h"
static char path[PATH_MAX] = { 0, };
static char *pathp = path;
@@ -189,6 +185,37 @@ static int walk_dir(const char *name)
return ret;
}
+/*
+ * A zero-length dedupe between two files should always succeed,
+ * so we can use this to test the presence of dedupe functionality.
+ */
+static bool check_ioctl_works(int fd)
+{
+ struct {
+ struct btrfs_ioctl_same_args args;
+ struct btrfs_ioctl_same_extent_info info;
+ } sa = {0};
+ struct stat sb;
+ static int cached = -1;
+ int ret;
+
+ if (cached >= 0)
+ return cached != 0;
+
+ ret = fstat(fd, &sb);
+ if (ret)
+ return false;
+
+ sa.args.dest_count = 1;
+ sa.args.length = 0;
+ sa.info.fd = fd;
+ sa.info.logical_offset = 0;
+ errno = 0;
+ ret = btrfs_extent_same(fd, &sa.args);
+ cached = !ret && !errno && !sa.info.status;
+ return cached;
+}
+
static int __add_file(const char *name, struct stat *st,
struct filerec **ret_file)
{
@@ -235,12 +262,10 @@ static int __add_file(const char *name, struct stat *st,
goto out;
}
- if (run_dedupe &&
- ((fs.f_type != BTRFS_SUPER_MAGIC &&
- fs.f_type != XFS_SB_MAGIC))) {
+ if (run_dedupe && !check_ioctl_works(fd)) {
close(fd);
- fprintf(stderr, "\"%s\": Can only dedupe files on btrfs or xfs "
- "(experimental)\n", name);
+ fprintf(stderr, "\"%s\": dedupe ioctl not supported on this "
+ "filesystem.\n", name);
return ENOSYS;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] duperemove: test presence of dedupe ioctl
2016-12-16 1:21 [PATCH v2] duperemove: test presence of dedupe ioctl Darrick J. Wong
@ 2016-12-16 7:53 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2016-12-16 7:53 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: mfasheh, xfs, Christoph Hellwig, linux-btrfs
Looks fine,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] duperemove: test presence of dedupe ioctl
2017-01-06 7:07 Darrick J. Wong
@ 2017-01-08 9:52 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2017-01-08 9:52 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: mfasheh, Christoph Hellwig, xfs, linux-btrfs
On Thu, Jan 05, 2017 at 11:07:32PM -0800, Darrick J. Wong wrote:
> Since a zero-length dedupe operation is guaranteed to succeed, use that
> to test whether or not this filesystem supports dedupe.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Didn't you already get my:
Reviewed-by: Christoph Hellwig <hch@lst.de>
earlier? If not feel free to add it.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] duperemove: test presence of dedupe ioctl
@ 2017-01-06 7:07 Darrick J. Wong
2017-01-08 9:52 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2017-01-06 7:07 UTC (permalink / raw)
To: mfasheh; +Cc: Christoph Hellwig, xfs, linux-btrfs
Since a zero-length dedupe operation is guaranteed to succeed, use that
to test whether or not this filesystem supports dedupe.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: declare variables on the stack instead of introducing fake types
---
file_scan.c | 45 +++++++++++++++++++++++++++++++++++----------
1 file changed, 35 insertions(+), 10 deletions(-)
diff --git a/file_scan.c b/file_scan.c
index 617f166..2708bfe 100644
--- a/file_scan.c
+++ b/file_scan.c
@@ -45,11 +45,7 @@
#include "file_scan.h"
#include "dbfile.h"
#include "util.h"
-
-/* This is not in linux/magic.h */
-#ifndef XFS_SB_MAGIC
-#define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
-#endif
+#include "btrfs-ioctl.h"
static char path[PATH_MAX] = { 0, };
static char *pathp = path;
@@ -189,6 +185,37 @@ static int walk_dir(const char *name)
return ret;
}
+/*
+ * A zero-length dedupe between two files should always succeed,
+ * so we can use this to test the presence of dedupe functionality.
+ */
+static bool check_ioctl_works(int fd)
+{
+ struct {
+ struct btrfs_ioctl_same_args args;
+ struct btrfs_ioctl_same_extent_info info;
+ } sa = {0};
+ struct stat sb;
+ static int cached = -1;
+ int ret;
+
+ if (cached >= 0)
+ return cached != 0;
+
+ ret = fstat(fd, &sb);
+ if (ret)
+ return false;
+
+ sa.args.dest_count = 1;
+ sa.args.length = 0;
+ sa.info.fd = fd;
+ sa.info.logical_offset = 0;
+ errno = 0;
+ ret = btrfs_extent_same(fd, &sa.args);
+ cached = !ret && !errno && !sa.info.status;
+ return cached;
+}
+
static int __add_file(const char *name, struct stat *st,
struct filerec **ret_file)
{
@@ -235,12 +262,10 @@ static int __add_file(const char *name, struct stat *st,
goto out;
}
- if (run_dedupe &&
- ((fs.f_type != BTRFS_SUPER_MAGIC &&
- fs.f_type != XFS_SB_MAGIC))) {
+ if (run_dedupe && !check_ioctl_works(fd)) {
close(fd);
- fprintf(stderr, "\"%s\": Can only dedupe files on btrfs or xfs "
- "(experimental)\n", name);
+ fprintf(stderr, "\"%s\": dedupe ioctl not supported on this "
+ "filesystem.\n", name);
return ENOSYS;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-01-08 9:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-16 1:21 [PATCH v2] duperemove: test presence of dedupe ioctl Darrick J. Wong
2016-12-16 7:53 ` Christoph Hellwig
2017-01-06 7:07 Darrick J. Wong
2017-01-08 9:52 ` Christoph Hellwig
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.