From c2e96b492d25ac62bbb6611d95ff7abd792929e5 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Sun, 23 Jun 2024 09:35:09 -0700 Subject: [PATCH] add inode_attr_x interface for retention and projectid --- c_defs_linux.go | 20 ++++++++++++++++++-- scoutfs.go | 35 +++++++++++++++++++++++++++++++---- scoutfsdefs.go | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/c_defs_linux.go b/c_defs_linux.go index 6e48537..0540772 100644 --- a/c_defs_linux.go +++ b/c_defs_linux.go @@ -71,6 +71,7 @@ package scoutfs // typedef struct scoutfs_ioctl_get_quota_rules scoutfs_ioctl_get_quota_rules_t; // typedef struct scoutfs_ioctl_xattr_index_entry scoutfs_ioctl_xattr_index_entry_t; // typedef struct scoutfs_ioctl_read_xattr_index scoutfs_ioctl_read_xattr_index_t; +// typedef struct scoutfs_ioctl_inode_attr_x scoutfs_ioctl_inode_attr_x_t; import "C" const IOCQUERYINODES = C.SCOUTFS_IOC_WALK_INODES @@ -91,8 +92,6 @@ const IOCGETREFERRINGENTRIES = C.SCOUTFS_IOC_GET_REFERRING_ENTRIES const IOCGETQUOTARULES = C.SCOUTFS_IOC_GET_QUOTA_RULES const IOCDELQUOTARULE = C.SCOUTFS_IOC_DEL_QUOTA_RULE const IOCADDQUOTARULE = C.SCOUTFS_IOC_ADD_QUOTA_RULE -const IOCGETPROJECTID = C.SCOUTFS_IOC_GET_PROJECT_ID -const IOCSETPROJECTID = C.SCOUTFS_IOC_SET_PROJECT_ID const IOCREADXATTRINDEX = C.SCOUTFS_IOC_READ_XATTR_INDEX const QUERYINODESMETASEQ = C.SCOUTFS_IOC_WALK_INODES_META_SEQ @@ -108,6 +107,22 @@ const MBSTAGEFLG = C.SCOUTFS_IOC_MB_STAGE const DIRENTFLAGLAST = C.SCOUTFS_IOCTL_DIRENT_FLAG_LAST +const IOCIAXFSIZEOFFLINE = C.SCOUTFS_IOC_IAX_F_SIZE_OFFLINE +const IOCIAXBRETENTION = C.SCOUTFS_IOC_IAX_B_RETENTION +const IOCIAXMETASEQ = C.SCOUTFS_IOC_IAX_META_SEQ +const IOCIAXDATASEQ = C.SCOUTFS_IOC_IAX_DATA_SEQ +const IOCIAXDATAVERSION = C.SCOUTFS_IOC_IAX_DATA_VERSION +const IOCIAXONLINEBLOCKS = C.SCOUTFS_IOC_IAX_ONLINE_BLOCKS +const IOCIAXOFFLINEBLOCKS = C.SCOUTFS_IOC_IAX_OFFLINE_BLOCKS +const IOCIAXCTIME = C.SCOUTFS_IOC_IAX_CTIME +const IOCIAXCRTIME = C.SCOUTFS_IOC_IAX_CRTIME +const IOCIAXSIZE = C.SCOUTFS_IOC_IAX_SIZE +const IOCIAXRETENTION = C.SCOUTFS_IOC_IAX_RETENTION +const IOCIAXPROJECTID = C.SCOUTFS_IOC_IAX_PROJECT_ID +const IOCIAXBITS = C.SCOUTFS_IOC_IAX__BITS +const IOCGETATTRX = C.SCOUTFS_IOC_GET_ATTR_X +const IOCSETATTRX = C.SCOUTFS_IOC_SET_ATTR_X + type InodesEntry C.scoutfs_ioctl_walk_inodes_entry_t type queryInodes C.scoutfs_ioctl_walk_inodes_t type inoPath C.scoutfs_ioctl_ino_path_t @@ -132,6 +147,7 @@ type quotaRule C.scoutfs_ioctl_quota_rule_t type getQuotaRules C.scoutfs_ioctl_get_quota_rules_t type indexEntry C.scoutfs_ioctl_xattr_index_entry_t type readXattrIndex C.scoutfs_ioctl_read_xattr_index_t +type inodeAttrX C.scoutfs_ioctl_inode_attr_x_t const sizeofstatfsMore = C.sizeof_scoutfs_ioctl_statfs_more_t const sizeofxattrTotal = C.sizeof_scoutfs_ioctl_xattr_total_t diff --git a/scoutfs.go b/scoutfs.go index 0a547b7..badcbd9 100644 --- a/scoutfs.go +++ b/scoutfs.go @@ -1653,16 +1653,43 @@ func quotaAdd(f *os.File, q QuotaRule) error { } func GetProjectID(f *os.File) (uint64, error) { - var projectid uint64 - _, err := scoutfsctl(f, IOCGETPROJECTID, unsafe.Pointer(&projectid)) - return projectid, err + var iax inodeAttrX + iax.X_mask = IOCIAXPROJECTID + _, err := scoutfsctl(f, IOCGETATTRX, unsafe.Pointer(&iax)) + return iax.Project_id, err } func SetProjectID(f *os.File, projectid uint64) error { - _, err := scoutfsctl(f, IOCSETPROJECTID, unsafe.Pointer(&projectid)) + var iax inodeAttrX + iax.X_mask = IOCIAXPROJECTID + iax.Project_id = projectid + _, err := scoutfsctl(f, IOCSETATTRX, unsafe.Pointer(&iax)) return err } +func SetRetention(f *os.File) error { + var iax inodeAttrX + iax.X_mask = IOCIAXRETENTION + iax.Bits = IOCIAXBRETENTION + _, err := scoutfsctl(f, IOCSETATTRX, unsafe.Pointer(&iax)) + return err +} + +func ClearRetention(f *os.File) error { + var iax inodeAttrX + iax.X_mask = IOCIAXRETENTION + _, err := scoutfsctl(f, IOCSETATTRX, unsafe.Pointer(&iax)) + return err +} + +func GetRetention(f *os.File) (bool, error) { + var iax inodeAttrX + iax.X_mask = IOCIAXRETENTION + _, err := scoutfsctl(f, IOCGETATTRX, unsafe.Pointer(&iax)) + return ((iax.X_mask&IOCIAXRETENTION == IOCIAXRETENTION) && + (iax.Bits&IOCIAXBRETENTION == IOCIAXBRETENTION)), err +} + type IndexSearch struct { // file handle for ioctls f *os.File diff --git a/scoutfsdefs.go b/scoutfsdefs.go index 8dafd20..27278c5 100644 --- a/scoutfsdefs.go +++ b/scoutfsdefs.go @@ -21,8 +21,6 @@ const IOCGETREFERRINGENTRIES = 0x4028e811 const IOCGETQUOTARULES = 0x8020e814 const IOCDELQUOTARULE = 0x4030e816 const IOCADDQUOTARULE = 0x4030e815 -const IOCGETPROJECTID = 0x8008e812 -const IOCSETPROJECTID = 0x4008e813 const IOCREADXATTRINDEX = 0x8048e817 const QUERYINODESMETASEQ = 0x0 @@ -38,6 +36,22 @@ const MBSTAGEFLG = 0x1 const DIRENTFLAGLAST = 0x1 +const IOCIAXFSIZEOFFLINE = 0x1 +const IOCIAXBRETENTION = 0x1 +const IOCIAXMETASEQ = 0x1 +const IOCIAXDATASEQ = 0x2 +const IOCIAXDATAVERSION = 0x4 +const IOCIAXONLINEBLOCKS = 0x8 +const IOCIAXOFFLINEBLOCKS = 0x10 +const IOCIAXCTIME = 0x20 +const IOCIAXCRTIME = 0x40 +const IOCIAXSIZE = 0x80 +const IOCIAXRETENTION = 0x100 +const IOCIAXPROJECTID = 0x200 +const IOCIAXBITS = 0x100 +const IOCGETATTRX = 0x4068e812 +const IOCSETATTRX = 0x4068e813 + type InodesEntry struct { Major uint64 Ino uint64 @@ -210,6 +224,22 @@ type readXattrIndex struct { Ptr uint64 Nr uint64 } +type inodeAttrX struct { + X_mask uint64 + X_flags uint64 + Meta_seq uint64 + Data_seq uint64 + Data_version uint64 + Online_blocks uint64 + Offline_blocks uint64 + Ctime_sec uint64 + Ctime_nsec uint32 + Crtime_nsec uint32 + Crtime_sec uint64 + Size uint64 + Bits uint64 + Project_id uint64 +} const sizeofstatfsMore = 0x30 const sizeofxattrTotal = 0x28