Skip to content

Commit 2d4e15e

Browse files
committed
libbtrfsutil: update internal header files (minor change)
Cumulative change sync with UAPI headers, rename and unify multiple inclusion macro names. Added defines: - BTRFS_QGROUP_INHERIT_FLAGS_SUPP - BTRFS_DEVICE_REMOVE_ARGS_MASK - BTRFS_SUBVOL_CREATE_ARGS_MASK - BTRFS_SUBVOL_DELETE_ARGS_MASK - BTRFS_DEFRAG_RANGE_FLAGS_SUPP Removed defines: - BTRFS_BALANCE_CTL_RESUME Added structures: - struct btrfs_ioctl_encoded_io_args (and related defines) - btrfs_ioctl_subvol_wait (and related defines) Added ioctl definitions: - BTRFS_IOC_ENCODED_READ - BTRFS_IOC_ENCODED_WRITE - BTRFS_IOC_SUBVOL_SYNC_WAIT Changes to the private header sync key types and other defines. Signed-off-by: David Sterba <[email protected]>
1 parent 6132b39 commit 2d4e15e

File tree

4 files changed

+270
-29
lines changed

4 files changed

+270
-29
lines changed

libbtrfsutil/btrfs.h

Lines changed: 194 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* Boston, MA 021110-1307, USA.
1818
*/
1919

20-
#ifndef _LINUX_BTRFS_H
21-
#define _LINUX_BTRFS_H
20+
#ifndef _LIBBTRFSUTIL_BTRFS_H_
21+
#define _LIBBTRFSUTIL_BTRFS_H_
22+
2223
#include <linux/types.h>
2324
#include <linux/ioctl.h>
2425

@@ -32,11 +33,18 @@ struct btrfs_ioctl_vol_args {
3233
__s64 fd;
3334
char name[BTRFS_PATH_NAME_MAX + 1];
3435
};
36+
#define BTRFS_DEVICE_PATH_NAME_MAX 1024
37+
#define BTRFS_SUBVOL_NAME_MAX 4039
3538

36-
#define BTRFS_DEVICE_PATH_NAME_MAX 1024
37-
#define BTRFS_SUBVOL_NAME_MAX 4039
39+
/*
40+
* Obsolete since 5.15, functionality removed in kernel 5.7:
41+
* BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
42+
*/
43+
#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
44+
#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
3845

3946
#define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3)
47+
4048
#define BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4)
4149

4250
#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \
@@ -78,6 +86,7 @@ struct btrfs_qgroup_limit {
7886
* struct btrfs_qgroup_inherit.flags
7987
*/
8088
#define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
89+
#define BTRFS_QGROUP_INHERIT_FLAGS_SUPP (BTRFS_QGROUP_INHERIT_SET_LIMITS)
8190

8291
struct btrfs_qgroup_inherit {
8392
__u64 flags;
@@ -94,21 +103,29 @@ struct btrfs_ioctl_qgroup_limit_args {
94103
};
95104

96105
/*
97-
* flags for subvolumes
106+
* Arguments for specification of subvolumes or devices, supporting by-name or
107+
* by-id and flags
98108
*
99-
* Used by:
100-
* struct btrfs_ioctl_vol_args_v2.flags
109+
* The set of supported flags depends on the ioctl
101110
*
102111
* BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls:
103112
* - BTRFS_IOC_SUBVOL_GETFLAGS
104113
* - BTRFS_IOC_SUBVOL_SETFLAGS
105114
*/
106-
/*
107-
* Obsolete since 5.15, functionality removed in kernel 5.7:
108-
* BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)
109-
*/
110-
#define BTRFS_SUBVOL_RDONLY (1ULL << 1)
111-
#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)
115+
116+
/* Supported flags for BTRFS_IOC_RM_DEV_V2 */
117+
#define BTRFS_DEVICE_REMOVE_ARGS_MASK \
118+
(BTRFS_DEVICE_SPEC_BY_ID)
119+
120+
/* Supported flags for BTRFS_IOC_SNAP_CREATE_V2 and BTRFS_IOC_SUBVOL_CREATE_V2 */
121+
#define BTRFS_SUBVOL_CREATE_ARGS_MASK \
122+
(BTRFS_SUBVOL_RDONLY | \
123+
BTRFS_SUBVOL_QGROUP_INHERIT)
124+
125+
/* Supported flags for BTRFS_IOC_SNAP_DESTROY_V2 */
126+
#define BTRFS_SUBVOL_DELETE_ARGS_MASK \
127+
(BTRFS_SUBVOL_SPEC_BY_ID)
128+
112129
struct btrfs_ioctl_vol_args_v2 {
113130
__s64 fd;
114131
__u64 transid;
@@ -227,7 +244,7 @@ struct btrfs_ioctl_dev_info_args {
227244
* Optional, out.
228245
*
229246
* Showing the fsid of the device, allowing user space to check if this
230-
* device is a seed one.
247+
* device is a seeding one.
231248
*
232249
* Introduced in v6.3, thus user space still needs to check if kernel
233250
* changed this value. Older kernel will not touch the values here.
@@ -322,7 +339,6 @@ struct btrfs_ioctl_feature_flags {
322339
/* balance control ioctl modes */
323340
#define BTRFS_BALANCE_CTL_PAUSE 1
324341
#define BTRFS_BALANCE_CTL_CANCEL 2
325-
#define BTRFS_BALANCE_CTL_RESUME 3
326342

327343
/*
328344
* this is packed, because it should be exactly the same as its disk
@@ -577,6 +593,7 @@ struct btrfs_ioctl_search_args_v2 {
577593
__u64 buf[0]; /* out - found items */
578594
};
579595

596+
/* With a @src_length of zero, the range from @src_offset->EOF is cloned! */
580597
struct btrfs_ioctl_clone_range_args {
581598
__s64 src_fd;
582599
__u64 src_offset, src_length;
@@ -591,6 +608,9 @@ struct btrfs_ioctl_clone_range_args {
591608
*/
592609
#define BTRFS_DEFRAG_RANGE_COMPRESS 1
593610
#define BTRFS_DEFRAG_RANGE_START_IO 2
611+
#define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | \
612+
BTRFS_DEFRAG_RANGE_START_IO)
613+
594614
struct btrfs_ioctl_defrag_range_args {
595615
/* start of the defrag operation */
596616
__u64 start;
@@ -895,6 +915,157 @@ struct btrfs_ioctl_get_subvol_rootref_args {
895915
__u8 align[7];
896916
};
897917

918+
/*
919+
* Data and metadata for an encoded read or write.
920+
*
921+
* Encoded I/O bypasses any encoding automatically done by the filesystem (e.g.,
922+
* compression). This can be used to read the compressed contents of a file or
923+
* write pre-compressed data directly to a file.
924+
*
925+
* BTRFS_IOC_ENCODED_READ and BTRFS_IOC_ENCODED_WRITE are essentially
926+
* preadv/pwritev with additional metadata about how the data is encoded and the
927+
* size of the unencoded data.
928+
*
929+
* BTRFS_IOC_ENCODED_READ fills the given iovecs with the encoded data, fills
930+
* the metadata fields, and returns the size of the encoded data. It reads one
931+
* extent per call. It can also read data which is not encoded.
932+
*
933+
* BTRFS_IOC_ENCODED_WRITE uses the metadata fields, writes the encoded data
934+
* from the iovecs, and returns the size of the encoded data. Note that the
935+
* encoded data is not validated when it is written; if it is not valid (e.g.,
936+
* it cannot be decompressed), then a subsequent read may return an error.
937+
*
938+
* Since the filesystem page cache contains decoded data, encoded I/O bypasses
939+
* the page cache. Encoded I/O requires CAP_SYS_ADMIN.
940+
*/
941+
struct btrfs_ioctl_encoded_io_args {
942+
/* Input parameters for both reads and writes. */
943+
944+
/*
945+
* iovecs containing encoded data.
946+
*
947+
* For reads, if the size of the encoded data is larger than the sum of
948+
* iov[n].iov_len for 0 <= n < iovcnt, then the ioctl fails with
949+
* ENOBUFS.
950+
*
951+
* For writes, the size of the encoded data is the sum of iov[n].iov_len
952+
* for 0 <= n < iovcnt. This must be less than 128 KiB (this limit may
953+
* increase in the future). This must also be less than or equal to
954+
* unencoded_len.
955+
*/
956+
const struct iovec *iov;
957+
/* Number of iovecs. */
958+
unsigned long iovcnt;
959+
/*
960+
* Offset in file.
961+
*
962+
* For writes, must be aligned to the sector size of the filesystem.
963+
*/
964+
__s64 offset;
965+
/* Currently must be zero. */
966+
__u64 flags;
967+
968+
/*
969+
* For reads, the following members are output parameters that will
970+
* contain the returned metadata for the encoded data.
971+
* For writes, the following members must be set to the metadata for the
972+
* encoded data.
973+
*/
974+
975+
/*
976+
* Length of the data in the file.
977+
*
978+
* Must be less than or equal to unencoded_len - unencoded_offset. For
979+
* writes, must be aligned to the sector size of the filesystem unless
980+
* the data ends at or beyond the current end of the file.
981+
*/
982+
__u64 len;
983+
/*
984+
* Length of the unencoded (i.e., decrypted and decompressed) data.
985+
*
986+
* For writes, must be no more than 128 KiB (this limit may increase in
987+
* the future). If the unencoded data is actually longer than
988+
* unencoded_len, then it is truncated; if it is shorter, then it is
989+
* extended with zeroes.
990+
*/
991+
__u64 unencoded_len;
992+
/*
993+
* Offset from the first byte of the unencoded data to the first byte of
994+
* logical data in the file.
995+
*
996+
* Must be less than unencoded_len.
997+
*/
998+
__u64 unencoded_offset;
999+
/*
1000+
* BTRFS_ENCODED_IO_COMPRESSION_* type.
1001+
*
1002+
* For writes, must not be BTRFS_ENCODED_IO_COMPRESSION_NONE.
1003+
*/
1004+
__u32 compression;
1005+
/* Currently always BTRFS_ENCODED_IO_ENCRYPTION_NONE. */
1006+
__u32 encryption;
1007+
/*
1008+
* Reserved for future expansion.
1009+
*
1010+
* For reads, always returned as zero. Users should check for non-zero
1011+
* bytes. If there are any, then the kernel has a newer version of this
1012+
* structure with additional information that the user definition is
1013+
* missing.
1014+
*
1015+
* For writes, must be zeroed.
1016+
*/
1017+
__u8 reserved[64];
1018+
};
1019+
1020+
/* Data is not compressed. */
1021+
#define BTRFS_ENCODED_IO_COMPRESSION_NONE 0
1022+
/* Data is compressed as a single zlib stream. */
1023+
#define BTRFS_ENCODED_IO_COMPRESSION_ZLIB 1
1024+
/*
1025+
* Data is compressed as a single zstd frame with the windowLog compression
1026+
* parameter set to no more than 17.
1027+
*/
1028+
#define BTRFS_ENCODED_IO_COMPRESSION_ZSTD 2
1029+
/*
1030+
* Data is compressed sector by sector (using the sector size indicated by the
1031+
* name of the constant) with LZO1X and wrapped in the format documented in
1032+
* fs/btrfs/lzo.c. For writes, the compression sector size must match the
1033+
* filesystem sector size.
1034+
*/
1035+
#define BTRFS_ENCODED_IO_COMPRESSION_LZO_4K 3
1036+
#define BTRFS_ENCODED_IO_COMPRESSION_LZO_8K 4
1037+
#define BTRFS_ENCODED_IO_COMPRESSION_LZO_16K 5
1038+
#define BTRFS_ENCODED_IO_COMPRESSION_LZO_32K 6
1039+
#define BTRFS_ENCODED_IO_COMPRESSION_LZO_64K 7
1040+
#define BTRFS_ENCODED_IO_COMPRESSION_TYPES 8
1041+
1042+
/* Data is not encrypted. */
1043+
#define BTRFS_ENCODED_IO_ENCRYPTION_NONE 0
1044+
#define BTRFS_ENCODED_IO_ENCRYPTION_TYPES 1
1045+
1046+
/*
1047+
* Wait for subvolume cleaning process. This queries the kernel queue and it
1048+
* can change between the calls.
1049+
*
1050+
* - FOR_ONE - specify the subvolid
1051+
* - FOR_QUEUED - wait for all currently queued
1052+
* - COUNT - count number of queued
1053+
* - PEEK_FIRST - read which is the first in the queue (to be cleaned or being
1054+
* cleaned already), or 0 if the queue is empty
1055+
* - PEEK_LAST - read the last subvolid in the queue, or 0 if the queue is empty
1056+
*/
1057+
struct btrfs_ioctl_subvol_wait {
1058+
__u64 subvolid;
1059+
__u32 mode;
1060+
__u32 count;
1061+
};
1062+
1063+
#define BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE (0)
1064+
#define BTRFS_SUBVOL_SYNC_WAIT_FOR_QUEUED (1)
1065+
#define BTRFS_SUBVOL_SYNC_COUNT (2)
1066+
#define BTRFS_SUBVOL_SYNC_PEEK_FIRST (3)
1067+
#define BTRFS_SUBVOL_SYNC_PEEK_LAST (4)
1068+
8981069
/* Error codes as returned by the kernel */
8991070
enum btrfs_err_code {
9001071
BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1,
@@ -1025,5 +1196,11 @@ enum btrfs_err_code {
10251196
struct btrfs_ioctl_ino_lookup_user_args)
10261197
#define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \
10271198
struct btrfs_ioctl_vol_args_v2)
1028-
1029-
#endif /* _LINUX_BTRFS_H */
1199+
#define BTRFS_IOC_ENCODED_READ _IOR(BTRFS_IOCTL_MAGIC, 64, \
1200+
struct btrfs_ioctl_encoded_io_args)
1201+
#define BTRFS_IOC_ENCODED_WRITE _IOW(BTRFS_IOCTL_MAGIC, 64, \
1202+
struct btrfs_ioctl_encoded_io_args)
1203+
#define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \
1204+
struct btrfs_ioctl_subvol_wait)
1205+
1206+
#endif /* _LIBBTRFSUTIL_BTRFS_H_ */

0 commit comments

Comments
 (0)