[systemd-devel] [PATCH v3] readahead: use BTRFS_IOC_DEFRAG_RANGE
Timofey Titovets
nefelim4ag at gmail.com
Mon Jul 21 10:23:25 PDT 2014
Just completed TODO:
* readahead: use BTRFS_IOC_DEFRAG_RANGE instead of BTRFS_IOC_DEFRAG
ioctl, with START_IO
commit d3fc81bd6a5a046b22600ac1204df220c93d2c15 refs/tags/v30
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 15 15:39:10 2011 +0200
update TODO
i no add this todo in TODO list (recursively todo %), and as this my
opinion may be not relevant with author.
As i understand start_io option force write data after defragment,
without buffering it in memory.
v1 -> v2
Fixed spelling in TODO
v2 -> v3
Deleted todo from code
Fix compilation issues
Delete fallback code, because BTRFS_IOC_DEFRAG_RANGE supported as 2.6.29
oldest longterm 2.6.32.63
----
TODO | 1 -
src/readahead/readahead-collect.c | 15 ++++++++++++---
src/shared/missing.h | 16 ++++++++++++++++
3 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/TODO b/TODO
index bfa06de..636d25f 100644
--- a/TODO
+++ b/TODO
@@ -570,7 +570,6 @@ Features:
* readahead:
- drop /.readahead on bigger upgrades with yum
- move readahead files into /var (look for them with .path units?)
- - readahead: use BTRFS_IOC_DEFRAG_RANGE instead of BTRFS_IOC_DEFRAG
ioctl, with START_IO
- readahead: when bumping /sys readahead variable save mtime and
compare later to detect changes
- readahead: make use of EXT4_IOC_MOVE_EXT, as used by
http://e4rat.sourceforge.net/
diff --git a/src/readahead/readahead-collect.c
b/src/readahead/readahead-collect.c
index c1afd0d..c641f9a 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -48,6 +48,10 @@
#include <linux/btrfs.h>
#endif
+#ifdef HAVE_BTRFS_IOCTL_H
+#include <btrfs/ioctl.h>
+#endif
+
#ifdef HAVE_FANOTIFY_INIT
#include <sys/fanotify.h>
#endif
@@ -78,10 +82,15 @@ static usec_t starttime;
#define SECTOR_TO_PTR(s) ULONG_TO_PTR((s)+1)
#define PTR_TO_SECTOR(p) (PTR_TO_ULONG(p)-1)
-static int btrfs_defrag(int fd) {
- struct btrfs_ioctl_vol_args data = { .fd = fd };
+static int btrfs_defrag(int fd){
+ static struct btrfs_ioctl_defrag_range_args range = {
+ .start = 0,
+ .len = (uint64_t)-1,
+ .flags = 2,
+ .extent_thresh = 1
+ };
- return ioctl(fd, BTRFS_IOC_DEFRAG, &data);
+ return ioctl(fd, BTRFS_IOC_DEFRAG_RANGE, &range);
}
static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
diff --git a/src/shared/missing.h b/src/shared/missing.h
index 818d704..8f54dc8 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -186,6 +186,17 @@ static inline int fanotify_mark(int fanotify_fd,
unsigned int flags, uint64_t ma
#define BTRFS_UUID_SIZE 16
#endif
+#ifndef HAVE_BTRFS_IOCTL_H
+struct btrfs_ioctl_defrag_range_args {
+ uint64_t start; /* start byte = 0 */
+ uint64_t len; /* whole file uint64_t-1 */
+ uint64_t flags; /* start_io 2 */
+ uint32_t extent_thresh; /* rewrite extents 0 */
+ uint32_t compress_type; /* unspecified -> zlib */
+ uint32_t unused[4]; /* reserved */
+};
+#endif
+
#ifndef HAVE_LINUX_BTRFS_H
struct btrfs_ioctl_vol_args {
int64_t fd;
@@ -213,6 +224,11 @@ struct btrfs_ioctl_fs_info_args {
#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, struct
btrfs_ioctl_vol_args)
#endif
+#ifndef BTRFS_IOC_DEFRAG_RANGE
+#define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
+ struct
btrfs_ioctl_defrag_range_args)
+#endif
+
#ifndef BTRFS_IOC_DEV_INFO
#define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
struct btrfs_ioctl_dev_info_args)
More information about the systemd-devel
mailing list