Commit 646ddf0c authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Chandan Babu R

xfs: clean up the xfs_reserve_blocks interface

xfs_reserve_blocks has a very odd interface that can only be explained
by it directly deriving from the IRIX fcntl handler back in the day.

Split reporting out the reserved blocks out of xfs_reserve_blocks into
the only caller that cares.  This means that the value reported from
XFS_IOC_SET_RESBLKS isn't atomically sampled in the same critical
section as when it was set anymore, but as the values could change
right after setting them anyway that does not matter.  It does
provide atomic sampling of both values for XFS_IOC_GET_RESBLKS now,
though.

Also pass a normal scalar integer value for the requested value instead
of the pointless pointer.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>
parent c2c2620d
...@@ -344,43 +344,20 @@ xfs_growfs_log( ...@@ -344,43 +344,20 @@ xfs_growfs_log(
} }
/* /*
* exported through ioctl XFS_IOC_SET_RESBLKS & XFS_IOC_GET_RESBLKS
*
* xfs_reserve_blocks is called to set m_resblks
* in the in-core mount table. The number of unused reserved blocks
* is kept in m_resblks_avail.
*
* Reserve the requested number of blocks if available. Otherwise return * Reserve the requested number of blocks if available. Otherwise return
* as many as possible to satisfy the request. The actual number * as many as possible to satisfy the request. The actual number
* reserved are returned in outval * reserved are returned in outval.
*
* A null inval pointer indicates that only the current reserved blocks
* available should be returned no settings are changed.
*/ */
int int
xfs_reserve_blocks( xfs_reserve_blocks(
xfs_mount_t *mp, struct xfs_mount *mp,
uint64_t *inval, uint64_t request)
xfs_fsop_resblks_t *outval)
{ {
int64_t lcounter, delta; int64_t lcounter, delta;
int64_t fdblks_delta = 0; int64_t fdblks_delta = 0;
uint64_t request;
int64_t free; int64_t free;
int error = 0; int error = 0;
/* If inval is null, report current values and return */
if (inval == (uint64_t *)NULL) {
if (!outval)
return -EINVAL;
outval->resblks = mp->m_resblks;
outval->resblks_avail = mp->m_resblks_avail;
return 0;
}
request = *inval;
/* /*
* With per-cpu counters, this becomes an interesting problem. we need * With per-cpu counters, this becomes an interesting problem. we need
* to work out if we are freeing or allocation blocks first, then we can * to work out if we are freeing or allocation blocks first, then we can
...@@ -450,11 +427,6 @@ xfs_reserve_blocks( ...@@ -450,11 +427,6 @@ xfs_reserve_blocks(
spin_lock(&mp->m_sb_lock); spin_lock(&mp->m_sb_lock);
} }
out: out:
if (outval) {
outval->resblks = mp->m_resblks;
outval->resblks_avail = mp->m_resblks_avail;
}
spin_unlock(&mp->m_sb_lock); spin_unlock(&mp->m_sb_lock);
return error; return error;
} }
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
extern int xfs_growfs_data(struct xfs_mount *mp, struct xfs_growfs_data *in); extern int xfs_growfs_data(struct xfs_mount *mp, struct xfs_growfs_data *in);
extern int xfs_growfs_log(struct xfs_mount *mp, struct xfs_growfs_log *in); extern int xfs_growfs_log(struct xfs_mount *mp, struct xfs_growfs_log *in);
extern int xfs_reserve_blocks(xfs_mount_t *mp, uint64_t *inval, int xfs_reserve_blocks(struct xfs_mount *mp, uint64_t request);
xfs_fsop_resblks_t *outval);
extern int xfs_fs_goingdown(xfs_mount_t *mp, uint32_t inflags); extern int xfs_fs_goingdown(xfs_mount_t *mp, uint32_t inflags);
extern int xfs_fs_reserve_ag_blocks(struct xfs_mount *mp); extern int xfs_fs_reserve_ag_blocks(struct xfs_mount *mp);
......
...@@ -1881,7 +1881,6 @@ xfs_ioctl_getset_resblocks( ...@@ -1881,7 +1881,6 @@ xfs_ioctl_getset_resblocks(
struct xfs_mount *mp = XFS_I(file_inode(filp))->i_mount; struct xfs_mount *mp = XFS_I(file_inode(filp))->i_mount;
struct xfs_fsop_resblks fsop = { }; struct xfs_fsop_resblks fsop = { };
int error; int error;
uint64_t in;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
...@@ -1896,17 +1895,17 @@ xfs_ioctl_getset_resblocks( ...@@ -1896,17 +1895,17 @@ xfs_ioctl_getset_resblocks(
error = mnt_want_write_file(filp); error = mnt_want_write_file(filp);
if (error) if (error)
return error; return error;
in = fsop.resblks; error = xfs_reserve_blocks(mp, fsop.resblks);
error = xfs_reserve_blocks(mp, &in, &fsop);
mnt_drop_write_file(filp); mnt_drop_write_file(filp);
if (error) if (error)
return error; return error;
} else {
error = xfs_reserve_blocks(mp, NULL, &fsop);
if (error)
return error;
} }
spin_lock(&mp->m_sb_lock);
fsop.resblks = mp->m_resblks;
fsop.resblks_avail = mp->m_resblks_avail;
spin_unlock(&mp->m_sb_lock);
if (copy_to_user(arg, &fsop, sizeof(fsop))) if (copy_to_user(arg, &fsop, sizeof(fsop)))
return -EFAULT; return -EFAULT;
return 0; return 0;
......
...@@ -637,7 +637,6 @@ xfs_mountfs( ...@@ -637,7 +637,6 @@ xfs_mountfs(
struct xfs_sb *sbp = &(mp->m_sb); struct xfs_sb *sbp = &(mp->m_sb);
struct xfs_inode *rip; struct xfs_inode *rip;
struct xfs_ino_geometry *igeo = M_IGEO(mp); struct xfs_ino_geometry *igeo = M_IGEO(mp);
uint64_t resblks;
uint quotamount = 0; uint quotamount = 0;
uint quotaflags = 0; uint quotaflags = 0;
int error = 0; int error = 0;
...@@ -974,8 +973,7 @@ xfs_mountfs( ...@@ -974,8 +973,7 @@ xfs_mountfs(
* we were already there on the last unmount. Warn if this occurs. * we were already there on the last unmount. Warn if this occurs.
*/ */
if (!xfs_is_readonly(mp)) { if (!xfs_is_readonly(mp)) {
resblks = xfs_default_resblks(mp); error = xfs_reserve_blocks(mp, xfs_default_resblks(mp));
error = xfs_reserve_blocks(mp, &resblks, NULL);
if (error) if (error)
xfs_warn(mp, xfs_warn(mp,
"Unable to allocate reserve blocks. Continuing without reserve pool."); "Unable to allocate reserve blocks. Continuing without reserve pool.");
...@@ -1053,7 +1051,6 @@ void ...@@ -1053,7 +1051,6 @@ void
xfs_unmountfs( xfs_unmountfs(
struct xfs_mount *mp) struct xfs_mount *mp)
{ {
uint64_t resblks;
int error; int error;
/* /*
...@@ -1090,8 +1087,7 @@ xfs_unmountfs( ...@@ -1090,8 +1087,7 @@ xfs_unmountfs(
* we only every apply deltas to the superblock and hence the incore * we only every apply deltas to the superblock and hence the incore
* value does not matter.... * value does not matter....
*/ */
resblks = 0; error = xfs_reserve_blocks(mp, 0);
error = xfs_reserve_blocks(mp, &resblks, NULL);
if (error) if (error)
xfs_warn(mp, "Unable to free reserved block pool. " xfs_warn(mp, "Unable to free reserved block pool. "
"Freespace may not be correct on next mount."); "Freespace may not be correct on next mount.");
......
...@@ -906,10 +906,8 @@ xfs_fs_statfs( ...@@ -906,10 +906,8 @@ xfs_fs_statfs(
STATIC void STATIC void
xfs_save_resvblks(struct xfs_mount *mp) xfs_save_resvblks(struct xfs_mount *mp)
{ {
uint64_t resblks = 0;
mp->m_resblks_save = mp->m_resblks; mp->m_resblks_save = mp->m_resblks;
xfs_reserve_blocks(mp, &resblks, NULL); xfs_reserve_blocks(mp, 0);
} }
STATIC void STATIC void
...@@ -923,7 +921,7 @@ xfs_restore_resvblks(struct xfs_mount *mp) ...@@ -923,7 +921,7 @@ xfs_restore_resvblks(struct xfs_mount *mp)
} else } else
resblks = xfs_default_resblks(mp); resblks = xfs_default_resblks(mp);
xfs_reserve_blocks(mp, &resblks, NULL); xfs_reserve_blocks(mp, resblks);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment