From: Yu Watanabe Date: Mon, 24 Oct 2022 20:35:04 +0000 (+0900) Subject: btrfs-util: move btrfs_defrag_fd() from fd-util.[ch] X-Git-Tag: v252~42 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4117366a283657295264723e559d7ead79a7cfd3;p=thirdparty%2Fsystemd.git btrfs-util: move btrfs_defrag_fd() from fd-util.[ch] After d71ece3f0b85c7a3decc50143b68ac07fc5831ae, the function is not used in libbasic or libsystemd anymore. Let's move it to more appropriate place. --- diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 6c85a34896c..cee20a9a815 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -2,7 +2,6 @@ #include #include -#include #if WANT_LINUX_FS_H #include #endif @@ -779,20 +778,6 @@ int read_nr_open(void) { return 1024 * 1024; } -/* This is here because it's fd-related and is called from sd-journal code. Other btrfs-related utilities are - * in src/shared, but libsystemd must not link to libsystemd-shared, see docs/ARCHITECTURE.md. */ -int btrfs_defrag_fd(int fd) { - int r; - - assert(fd >= 0); - - r = fd_verify_regular(fd); - if (r < 0) - return r; - - return RET_NERRNO(ioctl(fd, BTRFS_IOC_DEFRAG, NULL)); -} - int fd_get_diskseq(int fd, uint64_t *ret) { uint64_t diskseq; diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 8543d0d5eaa..d9896e27e8d 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -108,7 +108,6 @@ static inline int make_null_stdio(void) { int fd_reopen(int fd, int flags); int read_nr_open(void); -int btrfs_defrag_fd(int fd); int fd_get_diskseq(int fd, uint64_t *ret); /* The maximum length a buffer for a /proc/self/fd/ path needs */ diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 5e3bcbb6e41..58ba286a240 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -739,6 +739,18 @@ int btrfs_subvol_get_subtree_quota(const char *path, uint64_t subvol_id, BtrfsQu return btrfs_subvol_get_subtree_quota_fd(fd, subvol_id, ret); } +int btrfs_defrag_fd(int fd) { + int r; + + assert(fd >= 0); + + r = fd_verify_regular(fd); + if (r < 0) + return r; + + return RET_NERRNO(ioctl(fd, BTRFS_IOC_DEFRAG, NULL)); +} + int btrfs_defrag(const char *p) { _cleanup_close_ int fd = -1; diff --git a/src/shared/btrfs-util.h b/src/shared/btrfs-util.h index b67a4c10fe8..5f568f23528 100644 --- a/src/shared/btrfs-util.h +++ b/src/shared/btrfs-util.h @@ -52,6 +52,7 @@ int btrfs_clone_range(int infd, uint64_t in_offset, int ofd, uint64_t out_offset int btrfs_get_block_device_fd(int fd, dev_t *dev); int btrfs_get_block_device(const char *path, dev_t *dev); +int btrfs_defrag_fd(int fd); int btrfs_defrag(const char *p); int btrfs_quota_enable_fd(int fd, bool b);