summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-01-05 17:46:10 -0800
committerDarrick J. Wong <djwong@kernel.org>2021-03-25 17:08:47 -0700
commit833dca9d1fee7fc1d2c97221d2c29989cfae0aab (patch)
tree2489cb733e603ef226673b0b9e7ff0fc0d5bf710
parent88393a1b0fcbeda9502a9289c01ae0a08fca8ab1 (diff)
xfs: enable userspace to hide an AG from allocation
Add an administrative interface so that userspace can hide an allocation group from block allocation. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/libxfs/xfs_ag.c55
-rw-r--r--fs/xfs/libxfs/xfs_fs.h5
-rw-r--r--fs/xfs/xfs_ioctl.c4
3 files changed, 63 insertions, 1 deletions
diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
index 69b138dffd92..208e82ec9dd6 100644
--- a/fs/xfs/libxfs/xfs_ag.c
+++ b/fs/xfs/libxfs/xfs_ag.c
@@ -544,6 +544,55 @@ xfs_ag_extend_space(
XFS_AG_RESV_NONE);
}
+/* Compute the AG geometry flags. */
+static inline uint32_t
+xfs_ag_calc_geoflags(
+ struct xfs_perag *pag)
+{
+ uint32_t ret = 0;
+
+ if (pag->pagf_noalloc)
+ ret |= XFS_AG_FLAG_NOALLOC;
+
+ return ret;
+}
+
+/*
+ * Compare the current AG geometry flags against the flags in the AG geometry
+ * structure and update the AG state to reflect any changes, then update the
+ * struct to reflect the current status.
+ */
+static inline int
+xfs_ag_update_geoflags(
+ struct xfs_perag *pag,
+ struct xfs_ag_geometry *ageo,
+ uint32_t new_flags)
+{
+ uint32_t old_flags = xfs_ag_calc_geoflags(pag);
+ int error;
+
+ if (!(new_flags & XFS_AG_FLAG_UPDATE)) {
+ ageo->ag_flags = old_flags;
+ return 0;
+ }
+
+ if ((old_flags & XFS_AG_FLAG_NOALLOC) &&
+ !(new_flags & XFS_AG_FLAG_NOALLOC)) {
+ error = xfs_ag_clear_noalloc(pag);
+ if (error)
+ return error;
+ }
+ if (!(old_flags & XFS_AG_FLAG_NOALLOC) &&
+ (new_flags & XFS_AG_FLAG_NOALLOC)) {
+ error = xfs_ag_set_noalloc(pag);
+ if (error)
+ return error;
+ }
+
+ ageo->ag_flags = xfs_ag_calc_geoflags(pag);
+ return 0;
+}
+
/* Retrieve AG geometry. */
int
xfs_ag_get_geometry(
@@ -557,6 +606,7 @@ xfs_ag_get_geometry(
struct xfs_agf *agf;
struct xfs_perag *pag;
unsigned int freeblks;
+ uint32_t inflags = ageo->ag_flags;
int error;
if (agno >= mp->m_sb.sb_agcount)
@@ -572,6 +622,10 @@ xfs_ag_get_geometry(
pag = agi_bp->b_pag;
+ error = xfs_ag_update_geoflags(pag, ageo, inflags);
+ if (error)
+ goto out;
+
/* Fill out form. */
memset(ageo, 0, sizeof(*ageo));
ageo->ag_number = agno;
@@ -589,6 +643,7 @@ xfs_ag_get_geometry(
ageo->ag_freeblks = freeblks;
xfs_ag_geom_health(pag, ageo);
+out:
/* Release resources. */
xfs_buf_relse(agf_bp);
out_agi:
diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index febafb11fbd5..f45358df4b94 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -308,6 +308,11 @@ struct xfs_ag_geometry {
#define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9) /* reference counts */
#define XFS_AG_GEOM_SICK_INODES (1 << 10) /* bad inodes were seen */
+#define XFS_AG_FLAG_UPDATE (1 << 0) /* update flags */
+#define XFS_AG_FLAG_NOALLOC (1 << 1) /* do not allocate from this AG */
+#define XFS_AG_FLAG_ALL (XFS_AG_FLAG_UPDATE | \
+ XFS_AG_FLAG_NOALLOC)
+
/*
* Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT
*/
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 7d1de3401b9e..2a9f1a798f73 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1042,10 +1042,12 @@ xfs_ioc_ag_geometry(
if (copy_from_user(&ageo, arg, sizeof(ageo)))
return -EFAULT;
- if (ageo.ag_flags)
+ if (ageo.ag_flags & ~XFS_AG_FLAG_ALL)
return -EINVAL;
if (memchr_inv(&ageo.ag_reserved, 0, sizeof(ageo.ag_reserved)))
return -EINVAL;
+ if ((ageo.ag_flags & XFS_AG_FLAG_UPDATE) && !capable(CAP_SYS_ADMIN))
+ return -EPERM;
error = xfs_ag_get_geometry(mp, ageo.ag_number, &ageo);
if (error)