diff options
author | Dave Chinner <david@fromorbit.com> | 2015-02-01 18:22:53 -0500 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2015-02-01 18:22:53 -0500 |
commit | 23bd0735cfdf5322170a9ef48c7d47c2e6567ba8 (patch) | |
tree | ee21ef48c72c9ccfe244b4673df70fd9fbb64329 /fs/xfs/xfs_ioctl.c | |
parent | d4388d3c0988ec00787ad1f8e63b5e2a6abef1dc (diff) |
xfs: factor projid hint checking out of xfs_ioctl_setattr
The project ID change checking is one of the few remaining open
coded checks in xfs_ioctl_setattr(). Factor it into a helper
function so that the setattr code mostly becomes a flow of check
and action helpers, making it easier to read and follow.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs/xfs_ioctl.c')
-rw-r--r-- | fs/xfs/xfs_ioctl.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 9f808539fc61..1f186d2eec06 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c | |||
@@ -1142,6 +1142,34 @@ xfs_ioctl_setattr_check_extsize( | |||
1142 | return 0; | 1142 | return 0; |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | int | ||
1146 | xfs_ioctl_setattr_check_projid( | ||
1147 | struct xfs_inode *ip, | ||
1148 | struct fsxattr *fa) | ||
1149 | { | ||
1150 | /* Disallow 32bit project ids if projid32bit feature is not enabled. */ | ||
1151 | if (fa->fsx_projid > (__uint16_t)-1 && | ||
1152 | !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb)) | ||
1153 | return -EINVAL; | ||
1154 | |||
1155 | /* | ||
1156 | * Project Quota ID state is only allowed to change from within the init | ||
1157 | * namespace. Enforce that restriction only if we are trying to change | ||
1158 | * the quota ID state. Everything else is allowed in user namespaces. | ||
1159 | */ | ||
1160 | if (current_user_ns() == &init_user_ns) | ||
1161 | return 0; | ||
1162 | |||
1163 | if (xfs_get_projid(ip) != fa->fsx_projid) | ||
1164 | return -EINVAL; | ||
1165 | if ((fa->fsx_xflags & XFS_XFLAG_PROJINHERIT) != | ||
1166 | (ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)) | ||
1167 | return -EINVAL; | ||
1168 | |||
1169 | return 0; | ||
1170 | } | ||
1171 | |||
1172 | |||
1145 | 1173 | ||
1146 | STATIC int | 1174 | STATIC int |
1147 | xfs_ioctl_setattr( | 1175 | xfs_ioctl_setattr( |
@@ -1157,25 +1185,9 @@ xfs_ioctl_setattr( | |||
1157 | 1185 | ||
1158 | trace_xfs_ioctl_setattr(ip); | 1186 | trace_xfs_ioctl_setattr(ip); |
1159 | 1187 | ||
1160 | /* | 1188 | code = xfs_ioctl_setattr_check_projid(ip, fa); |
1161 | * Disallow 32bit project ids when projid32bit feature is not enabled. | 1189 | if (code) |
1162 | */ | 1190 | return code; |
1163 | if (fa->fsx_projid > (__uint16_t)-1 && | ||
1164 | !xfs_sb_version_hasprojid32bit(&ip->i_mount->m_sb)) | ||
1165 | return -EINVAL; | ||
1166 | |||
1167 | /* | ||
1168 | * Project Quota ID state is only allowed to change from within the init | ||
1169 | * namespace. Enforce that restriction only if we are trying to change | ||
1170 | * the quota ID state. Everything else is allowed in user namespaces. | ||
1171 | */ | ||
1172 | if (current_user_ns() != &init_user_ns) { | ||
1173 | if (xfs_get_projid(ip) != fa->fsx_projid) | ||
1174 | return -EINVAL; | ||
1175 | if ((fa->fsx_xflags & XFS_XFLAG_PROJINHERIT) != | ||
1176 | (ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)) | ||
1177 | return -EINVAL; | ||
1178 | } | ||
1179 | 1191 | ||
1180 | /* | 1192 | /* |
1181 | * If disk quotas is on, we make sure that the dquots do exist on disk, | 1193 | * If disk quotas is on, we make sure that the dquots do exist on disk, |