From a98c0d67b630b3d349bca6573c543d6bdc726d30 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 17 Sep 2024 09:58:11 -0400 Subject: [PATCH 1/2] common: remove unused sync_filesystem.h Signed-off-by: Casey Bodley --- src/common/sync_filesystem.h | 56 ------------------------------------ 1 file changed, 56 deletions(-) delete mode 100644 src/common/sync_filesystem.h diff --git a/src/common/sync_filesystem.h b/src/common/sync_filesystem.h deleted file mode 100644 index f457f655df5..00000000000 --- a/src/common/sync_filesystem.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2011 New Dream Network - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#ifndef CEPH_SYNC_FILESYSTEM_H -#define CEPH_SYNC_FILESYSTEM_H - -#include - -#if defined(__linux__) -#include -#include -#include "os/fs/btrfs_ioctl.h" -#endif - -inline int sync_filesystem(int fd) -{ - /* On Linux, newer versions of glibc have a function called syncfs that - * performs a sync on only one filesystem. If we don't have this call, we - * have to fall back on sync(), which synchronizes every filesystem on the - * computer. */ -#ifdef HAVE_SYS_SYNCFS - if (syncfs(fd) == 0) - return 0; -#elif defined(SYS_syncfs) - if (syscall(SYS_syncfs, fd) == 0) - return 0; -#elif defined(__NR_syncfs) - if (syscall(__NR_syncfs, fd) == 0) - return 0; -#endif - -#if defined(HAVE_SYS_SYNCFS) || defined(SYS_syncfs) || defined(__NR_syncfs) - else if (errno == ENOSYS) { - sync(); - return 0; - } else { - return -errno; - } -#else - sync(); - return 0; -#endif -} - -#endif From 9d454bd8be670ee7a65e0ce87222f52feaefd3a6 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 17 Sep 2024 10:00:26 -0400 Subject: [PATCH 2/2] os: remove unused btrfs_ioctl.h and tests remove unused header whose GPL license was potentially problematic Fixes: https://tracker.ceph.com/issues/68083 Signed-off-by: Casey Bodley --- COPYING | 4 - qa/Makefile | 2 +- qa/btrfs/.gitignore | 3 - qa/btrfs/Makefile | 11 -- qa/btrfs/clone_range.c | 35 ------ qa/btrfs/create_async_snap.c | 34 ------ qa/btrfs/test_async_snap.c | 83 ------------- qa/btrfs/test_rmdir_async_snap.c | 62 ---------- src/btrfs_ioc_test.c | 171 -------------------------- src/os/fs/btrfs_ioctl.h | 201 ------------------------------- 10 files changed, 1 insertion(+), 605 deletions(-) delete mode 100644 qa/btrfs/.gitignore delete mode 100644 qa/btrfs/Makefile delete mode 100644 qa/btrfs/clone_range.c delete mode 100644 qa/btrfs/create_async_snap.c delete mode 100644 qa/btrfs/test_async_snap.c delete mode 100644 qa/btrfs/test_rmdir_async_snap.c delete mode 100644 src/btrfs_ioc_test.c delete mode 100644 src/os/fs/btrfs_ioctl.h diff --git a/COPYING b/COPYING index 509306e1699..28b93b21935 100644 --- a/COPYING +++ b/COPYING @@ -29,10 +29,6 @@ Files: src/mount/canonicalize.c Copyright: Copyright (C) 1993 Rick Sladkey License: LGPL-2 or later -Files: src/os/btrfs_ioctl.h -Copyright: Copyright (C) 2007 Oracle. All rights reserved. -License: GPL2 (see COPYING-GPL2) - Files: src/include/ceph_hash.cc Copyright: None License: Public domain diff --git a/qa/Makefile b/qa/Makefile index ad655b7e743..05dc834adbd 100644 --- a/qa/Makefile +++ b/qa/Makefile @@ -1,4 +1,4 @@ -DIRS= workunits btrfs +DIRS= workunits all: for d in $(DIRS) ; do ( cd $$d ; $(MAKE) all ) ; done diff --git a/qa/btrfs/.gitignore b/qa/btrfs/.gitignore deleted file mode 100644 index 530c1b5b4ed..00000000000 --- a/qa/btrfs/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/clone_range -/test_async_snap -/create_async_snap diff --git a/qa/btrfs/Makefile b/qa/btrfs/Makefile deleted file mode 100644 index be95ecfd3cd..00000000000 --- a/qa/btrfs/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -CFLAGS = -Wall -Wextra -D_GNU_SOURCE - -TARGETS = clone_range test_async_snap create_async_snap - -.c: - $(CC) $(CFLAGS) $@.c -o $@ - -all: $(TARGETS) - -clean: - rm $(TARGETS) diff --git a/qa/btrfs/clone_range.c b/qa/btrfs/clone_range.c deleted file mode 100644 index 0a88e160131..00000000000 --- a/qa/btrfs/clone_range.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -#include -#include "../../src/os/btrfs_ioctl.h" -#include -#include - -int main(int argc, char **argv) -{ - struct btrfs_ioctl_clone_range_args ca; - int dfd; - int r; - - if (argc < 6) { - printf("usage: %s \n", argv[0]); - exit(1); - } - - ca.src_fd = open(argv[1], O_RDONLY); - ca.src_offset = atoi(argv[2]); - ca.src_length = atoi(argv[3]); - dfd = open(argv[4], O_WRONLY|O_CREAT); - ca.dest_offset = atoi(argv[5]); - - r = ioctl(dfd, BTRFS_IOC_CLONE_RANGE, &ca); - printf("clone_range %s %lld %lld~%lld to %s %d %lld = %d %s\n", - argv[1], ca.src_fd, - ca.src_offset, ca.src_length, - argv[4], dfd, - ca.dest_offset, r, strerror(errno)); - return r; -} diff --git a/qa/btrfs/create_async_snap.c b/qa/btrfs/create_async_snap.c deleted file mode 100644 index 2ef22af7b45..00000000000 --- a/qa/btrfs/create_async_snap.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "../../src/os/btrfs_ioctl.h" - -struct btrfs_ioctl_vol_args_v2 va; - -int main(int argc, char **argv) -{ - int fd; - int r; - - if (argc != 3) { - printf("usage: %s \n", argv[0]); - return 1; - } - printf("creating snap ./%s from %s\n", argv[2], argv[1]); - fd = open(".", O_RDONLY); - va.fd = open(argv[1], O_RDONLY); - va.flags = BTRFS_SUBVOL_CREATE_ASYNC; - strcpy(va.name, argv[2]); - r = ioctl(fd, BTRFS_IOC_SNAP_CREATE_V2, (unsigned long long)&va); - printf("result %d\n", r ? -errno:0); - return r; -} diff --git a/qa/btrfs/test_async_snap.c b/qa/btrfs/test_async_snap.c deleted file mode 100644 index 211be95a61c..00000000000 --- a/qa/btrfs/test_async_snap.c +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "../../src/os/btrfs_ioctl.h" - -struct btrfs_ioctl_vol_args_v2 va; -struct btrfs_ioctl_vol_args vold; -int max = 4; - -void check_return(int r) -{ - if (r < 0) { - printf("********* failed with %d %s ********\n", errno, strerror(errno)); - exit(1); - } -} - -int main(int argc, char **argv) -{ - int num = 1000; - - if (argc > 1) - num = atoi(argv[1]); - printf("will do %d iterations\n", num); - - int cwd = open(".", O_RDONLY); - printf("cwd = %d\n", cwd); - while (num-- > 0) { - if (rand() % 10 == 0) { - __u64 transid; - int r; - printf("sync starting\n"); - r = ioctl(cwd, BTRFS_IOC_START_SYNC, &transid); - check_return(r); - printf("sync started, transid %lld, waiting\n", transid); - r = ioctl(cwd, BTRFS_IOC_WAIT_SYNC, &transid); - check_return(r); - printf("sync finished\n"); - } - - int i = rand() % max; - struct stat st; - va.fd = cwd; - sprintf(va.name, "test.%d", i); - va.transid = 0; - int r = stat(va.name, &st); - if (r < 0) { - if (rand() % 3 == 0) { - printf("snap create (sync) %s\n", va.name); - va.flags = 0; - r = ioctl(cwd, BTRFS_IOC_SNAP_CREATE_V2, &va); - check_return(r); - } else { - printf("snap create (async) %s\n", va.name); - va.flags = BTRFS_SUBVOL_CREATE_ASYNC; - r = ioctl(cwd, BTRFS_IOC_SNAP_CREATE_V2, &va); - check_return(r); - printf("snap created, transid %lld\n", va.transid); - if (rand() % 2 == 0) { - printf("waiting for async snap create\n"); - r = ioctl(cwd, BTRFS_IOC_WAIT_SYNC, &va.transid); - check_return(r); - } - } - } else { - printf("snap remove %s\n", va.name); - vold.fd = va.fd; - strcpy(vold.name, va.name); - r = ioctl(cwd, BTRFS_IOC_SNAP_DESTROY, &vold); - check_return(r); - } - } - return 0; -} diff --git a/qa/btrfs/test_rmdir_async_snap.c b/qa/btrfs/test_rmdir_async_snap.c deleted file mode 100644 index 5dafaacaaeb..00000000000 --- a/qa/btrfs/test_rmdir_async_snap.c +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "../../src/os/btrfs_ioctl.h" - -struct btrfs_ioctl_vol_args_v2 va; -struct btrfs_ioctl_vol_args vold; - -int main(int argc, char **argv) -{ - int num = 1000; - int i, r, fd; - char buf[30]; - - if (argc > 1) - num = atoi(argv[1]); - printf("will do %d iterations\n", num); - - fd = open(".", O_RDONLY); - vold.fd = 0; - strcpy(vold.name, "current"); - r = ioctl(fd, BTRFS_IOC_SUBVOL_CREATE, (unsigned long int)&vold); - printf("create current ioctl got %d\n", r ? errno:0); - if (r) - return 1; - - for (i=0; i -#include -#include -#include -#include -#include -#include -#include - -#include "common/safe_io.h" -#include "os/btrfs_ioctl.h" - -void do_open_wr(const char *fname, int *fd) -{ - *fd = open(fname, O_WRONLY | O_CREAT, 0644); - if (*fd < 0) { - perror("open"); - exit(1); - } -} - -void do_open_rd(const char *fname, int *fd) -{ - *fd = open(fname, O_RDONLY); - if (*fd < 0) { - perror("open"); - exit(1); - } -} - -void do_lseek(int fd, int ofs) -{ - int rc = lseek(fd, ofs, SEEK_SET); - if (rc < 0) { - perror("lseek"); - exit(1); - } -} - -void do_write(int fd, int len) -{ - char *buf = malloc(len); - int rc; - if (!buf) { - printf("not enough memory\n"); - exit(1); - } - - memset(buf, 0, len); - rc = safe_write(fd, buf, len); - if (rc) { - fprintf(stderr, "safe_write failed with error %d (%s)\n", - rc, strerror(rc)); - exit(1); - } - - if (rc != len) { - printf("invalid number of bytes written\n"); - exit(1); - } - - free(buf); -} - -void do_link(const char *old, const char *new) -{ - int rc = link(old, new); - if (rc < 0) { - perror("link"); - exit(1); - } -} - -void do_clone_range(int from, int to, int off, int len) -{ - struct btrfs_ioctl_clone_range_args a; - int r; - - a.src_fd = from; - a.src_offset = off; - a.src_length = len; - a.dest_offset = off; - r = ioctl(to, BTRFS_IOC_CLONE_RANGE, &a); - if (r < 0) { - perror("ioctl"); - exit(1); - } -} - -void do_snap_async(int fd, const char *name, unsigned long long *transid) -{ - struct btrfs_ioctl_async_vol_args async_args; - struct btrfs_ioctl_vol_args volargs; - int r; - - strcpy(volargs.name, name); - volargs.fd = fd; - - async_args.args = &volargs; - async_args.transid = transid; - - r = ioctl(fd, BTRFS_IOC_SNAP_CREATE_ASYNC, &async_args); - - if (r < 0) { - perror("ioctl"); - exit(1); - } -} - -void do_snap_destroy(int fd, const char *name) -{ - struct btrfs_ioctl_vol_args volargs; - int r; - - strcpy(volargs.name, name); - volargs.fd = 0; - - r = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &volargs); - - if (r < 0) { - perror("snap_destroy: ioctl"); - exit(1); - } -} - -void do_snap_wait(int fd, unsigned long long transid) -{ - int r = ioctl(fd, BTRFS_IOC_WAIT_SYNC, &transid); - if (r < 0) { - perror("do_snap_wait: ioctl"); - exit(1); - } -} - -void usage_exit(char *arg) -{ - printf("usage: %s \n", arg); - exit(1); -} - -#define TEMP_FILENAME "temp" -#define DEST_FILENAME "dest" -#define SRC_FILENAME "src" - -int main(int argc, char *argv[]) -{ - const char *base_dir; - const char *snap_name; - - int fd; - int i; - unsigned long long transid; - - if (argc < 3) - usage_exit(argv[0]); - - base_dir = argv[1]; - snap_name = argv[2]; - - for (i=0; i<10; i++) { - printf("%d\n", i); - do_open_rd(base_dir, &fd); - do_snap_async(fd, snap_name, &transid); - sleep(2); - //do_snap_wait(fd, transid); - do_snap_destroy(fd, snap_name); - close(fd); - } - - return 0; -} diff --git a/src/os/fs/btrfs_ioctl.h b/src/os/fs/btrfs_ioctl.h deleted file mode 100644 index 277498ca8dc..00000000000 --- a/src/os/fs/btrfs_ioctl.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) 2007 Oracle. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License v2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 021110-1307, USA. - */ - -#ifndef __IOCTL_ -#define __IOCTL_ - -#if defined(__linux__) -#include -#elif defined(__FreeBSD__) -#include -#endif - -#define BTRFS_IOCTL_MAGIC 0x94 -#define BTRFS_VOL_NAME_MAX 255 - -/* this should be 4k */ -#define BTRFS_PATH_NAME_MAX 4087 -struct btrfs_ioctl_vol_args { - __s64 fd; - char name[BTRFS_PATH_NAME_MAX + 1]; -}; - -#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) - -#define BTRFS_SUBVOL_NAME_MAX 4039 -struct btrfs_ioctl_vol_args_v2 { - __s64 fd; - __u64 transid; - __u64 flags; - __u64 unused[4]; - char name[BTRFS_SUBVOL_NAME_MAX + 1]; -}; - -#define BTRFS_INO_LOOKUP_PATH_MAX 4080 -struct btrfs_ioctl_ino_lookup_args { - __u64 treeid; - __u64 objectid; - char name[BTRFS_INO_LOOKUP_PATH_MAX]; -}; - -struct btrfs_ioctl_search_key { - /* which root are we searching. 0 is the tree of tree roots */ - __u64 tree_id; - - /* keys returned will be >= min and <= max */ - __u64 min_objectid; - __u64 max_objectid; - - /* keys returned will be >= min and <= max */ - __u64 min_offset; - __u64 max_offset; - - /* max and min transids to search for */ - __u64 min_transid; - __u64 max_transid; - - /* keys returned will be >= min and <= max */ - __u32 min_type; - __u32 max_type; - - /* - * how many items did userland ask for, and how many are we - * returning - */ - __u32 nr_items; - - /* align to 64 bits */ - __u32 unused; - - /* some extra for later */ - __u64 unused1; - __u64 unused2; - __u64 unused3; - __u64 unused4; -}; - -struct btrfs_ioctl_search_header { - __u64 transid; - __u64 objectid; - __u64 offset; - __u32 type; - __u32 len; -}; - -#define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) -/* - * the buf is an array of search headers where - * each header is followed by the actual item - * the type field is expanded to 32 bits for alignment - */ -struct btrfs_ioctl_search_args { - struct btrfs_ioctl_search_key key; - char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; -}; - -struct btrfs_ioctl_clone_range_args { - __s64 src_fd; - __u64 src_offset, src_length; - __u64 dest_offset; -}; - -/* flags for the defrag range ioctl */ -#define BTRFS_DEFRAG_RANGE_COMPRESS 1 -#define BTRFS_DEFRAG_RANGE_START_IO 2 - -struct btrfs_ioctl_defrag_range_args { - /* start of the defrag operation */ - __u64 start; - - /* number of bytes to defrag, use (u64)-1 to say all */ - __u64 len; - - /* - * flags for the operation, which can include turning - * on compression for this one defrag - */ - __u64 flags; - - /* - * any extent bigger than this will be considered - * already defragged. Use 0 to take the kernel default - * Use 1 to say every single extent must be rewritten - */ - __u32 extent_thresh; - - /* spare for later */ - __u32 unused[5]; -}; - -struct btrfs_ioctl_space_info { - __u64 flags; - __u64 total_bytes; - __u64 used_bytes; -}; - -struct btrfs_ioctl_space_args { - __u64 space_slots; - __u64 total_spaces; - struct btrfs_ioctl_space_info spaces[0]; -}; - -#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ - struct btrfs_ioctl_vol_args) -/* trans start and trans end are dangerous, and only for - * use by applications that know how to avoid the - * resulting deadlocks - */ -#define BTRFS_IOC_TRANS_START _IO(BTRFS_IOCTL_MAGIC, 6) -#define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7) -#define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8) - -#define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int) -#define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \ - struct btrfs_ioctl_vol_args) - -#define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \ - struct btrfs_ioctl_clone_range_args) - -#define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ - struct btrfs_ioctl_vol_args) -#define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \ - struct btrfs_ioctl_defrag_range_args) -#define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ - struct btrfs_ioctl_search_args) -#define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \ - struct btrfs_ioctl_ino_lookup_args) -#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64) -#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ - struct btrfs_ioctl_space_args) -#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64) -#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) -#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ - struct btrfs_ioctl_vol_args_v2) -#endif