summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-01-08 01:22:29 +0100
committerLennart Poettering <lennart@poettering.net>2015-01-08 01:22:29 +0100
commit11689d2a021d95a8447d938180e0962cd9439763 (patch)
tree83e4e1a10a219bd6344e995f445b4fe95ed54acb /src/shared/util.c
parent3c4230a5afb27faec2176d4642c0e2e145971b5c (diff)
journald: turn off COW for journal files on btrfs
btrfs' COW logic results in heavily fragment journal files, which is detrimental for perfomance. Hence, turn off COW for journal files as we create them. Turning off COW comes at the cost of data integrity guarantees, but this should be acceptable, given that we do our own checksumming, and generally have a pretty conservative write pattern. Also see discussion on linux-btrfs: http://www.spinics.net/lists/linux-btrfs/msg41001.html
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 6293e967c..88fd78ec8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -62,6 +62,7 @@
#include <sys/xattr.h>
#include <libgen.h>
#include <sys/statvfs.h>
+#include <linux/fs.h>
#undef basename
#ifdef HAVE_SYS_AUXV_H
@@ -7740,3 +7741,35 @@ int same_fd(int a, int b) {
return fa == fb;
}
+
+int chattr_fd(int fd, bool b, int mask) {
+ int old_attr, new_attr;
+
+ assert(fd >= 0);
+
+ if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0)
+ return -errno;
+
+ if (b)
+ new_attr = old_attr | mask;
+ else
+ new_attr = old_attr & ~mask;
+
+ if (new_attr == old_attr)
+ return 0;
+
+ if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0)
+ return -errno;
+
+ return 0;
+}
+
+int chattr_path(const char *p, bool b, int mask) {
+ _cleanup_close_ int fd = -1;
+
+ fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+ if (fd < 0)
+ return -errno;
+
+ return chattr_fd(fd, b, mask);
+}