On Thu, Oct 24, 2019 at 03:51:43PM +0800, Ian Kent wrote: > Refactor xfs_parseags(), move the entire token case block to a separate > function in an attempt to highlight the code that actually changes in > converting to use the new mount api. > > The only changes are what's needed to communicate the variables dsunit, > dswidth and iosizelog back to xfs_parseags(). > > Signed-off-by: Ian Kent <raven@xxxxxxxxxx> > Reviewed-by: Brian Foster <bfoster@xxxxxxxxxx> Looks ok, Reviewed-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --D > --- > fs/xfs/xfs_super.c | 290 ++++++++++++++++++++++++++++------------------------ > 1 file changed, 155 insertions(+), 135 deletions(-) > > diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c > index 92a37ac0b907..de0ab79536b3 100644 > --- a/fs/xfs/xfs_super.c > +++ b/fs/xfs/xfs_super.c > @@ -164,6 +164,156 @@ match_kstrtoint( > return ret; > } > > +static int > +xfs_fc_parse_param( > + int token, > + char *p, > + substring_t *args, > + struct xfs_mount *mp, > + int *dsunit, > + int *dswidth, > + uint8_t *iosizelog) > +{ > + int iosize = 0; > + > + switch (token) { > + case Opt_logbufs: > + if (match_int(args, &mp->m_logbufs)) > + return -EINVAL; > + return 0; > + case Opt_logbsize: > + if (match_kstrtoint(args, 10, &mp->m_logbsize)) > + return -EINVAL; > + return 0; > + case Opt_logdev: > + kfree(mp->m_logname); > + mp->m_logname = match_strdup(args); > + if (!mp->m_logname) > + return -ENOMEM; > + return 0; > + case Opt_rtdev: > + kfree(mp->m_rtname); > + mp->m_rtname = match_strdup(args); > + if (!mp->m_rtname) > + return -ENOMEM; > + return 0; > + case Opt_allocsize: > + if (match_kstrtoint(args, 10, &iosize)) > + return -EINVAL; > + *iosizelog = ffs(iosize) - 1; > + return 0; > + case Opt_grpid: > + case Opt_bsdgroups: > + mp->m_flags |= XFS_MOUNT_GRPID; > + return 0; > + case Opt_nogrpid: > + case Opt_sysvgroups: > + mp->m_flags &= ~XFS_MOUNT_GRPID; > + return 0; > + case Opt_wsync: > + mp->m_flags |= XFS_MOUNT_WSYNC; > + return 0; > + case Opt_norecovery: > + mp->m_flags |= XFS_MOUNT_NORECOVERY; > + return 0; > + case Opt_noalign: > + mp->m_flags |= XFS_MOUNT_NOALIGN; > + return 0; > + case Opt_swalloc: > + mp->m_flags |= XFS_MOUNT_SWALLOC; > + return 0; > + case Opt_sunit: > + if (match_int(args, dsunit)) > + return -EINVAL; > + return 0; > + case Opt_swidth: > + if (match_int(args, dswidth)) > + return -EINVAL; > + return 0; > + case Opt_inode32: > + mp->m_flags |= XFS_MOUNT_SMALL_INUMS; > + return 0; > + case Opt_inode64: > + mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; > + return 0; > + case Opt_nouuid: > + mp->m_flags |= XFS_MOUNT_NOUUID; > + return 0; > + case Opt_ikeep: > + mp->m_flags |= XFS_MOUNT_IKEEP; > + return 0; > + case Opt_noikeep: > + mp->m_flags &= ~XFS_MOUNT_IKEEP; > + return 0; > + case Opt_largeio: > + mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE; > + return 0; > + case Opt_nolargeio: > + mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; > + return 0; > + case Opt_attr2: > + mp->m_flags |= XFS_MOUNT_ATTR2; > + return 0; > + case Opt_noattr2: > + mp->m_flags &= ~XFS_MOUNT_ATTR2; > + mp->m_flags |= XFS_MOUNT_NOATTR2; > + return 0; > + case Opt_filestreams: > + mp->m_flags |= XFS_MOUNT_FILESTREAMS; > + return 0; > + case Opt_noquota: > + mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT; > + mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD; > + mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE; > + return 0; > + case Opt_quota: > + case Opt_uquota: > + case Opt_usrquota: > + mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE | > + XFS_UQUOTA_ENFD); > + return 0; > + case Opt_qnoenforce: > + case Opt_uqnoenforce: > + mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); > + mp->m_qflags &= ~XFS_UQUOTA_ENFD; > + return 0; > + case Opt_pquota: > + case Opt_prjquota: > + mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE | > + XFS_PQUOTA_ENFD); > + return 0; > + case Opt_pqnoenforce: > + mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); > + mp->m_qflags &= ~XFS_PQUOTA_ENFD; > + return 0; > + case Opt_gquota: > + case Opt_grpquota: > + mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE | > + XFS_GQUOTA_ENFD); > + return 0; > + case Opt_gqnoenforce: > + mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); > + mp->m_qflags &= ~XFS_GQUOTA_ENFD; > + return 0; > + case Opt_discard: > + mp->m_flags |= XFS_MOUNT_DISCARD; > + return 0; > + case Opt_nodiscard: > + mp->m_flags &= ~XFS_MOUNT_DISCARD; > + return 0; > +#ifdef CONFIG_FS_DAX > + case Opt_dax: > + mp->m_flags |= XFS_MOUNT_DAX; > + return 0; > +#endif > + default: > + xfs_warn(mp, "unknown mount option [%s].", p); > + return -EINVAL; > + } > + > + return 0; > +} > + > /* > * This function fills in xfs_mount_t fields based on mount args. > * Note: the superblock has _not_ yet been read in. > @@ -185,7 +335,6 @@ xfs_parseargs( > substring_t args[MAX_OPT_ARGS]; > int dsunit = 0; > int dswidth = 0; > - int iosize = 0; > uint8_t iosizelog = 0; > > /* > @@ -215,145 +364,16 @@ xfs_parseargs( > > while ((p = strsep(&options, ",")) != NULL) { > int token; > + int ret; > > if (!*p) > continue; > > token = match_token(p, tokens, args); > - switch (token) { > - case Opt_logbufs: > - if (match_int(args, &mp->m_logbufs)) > - return -EINVAL; > - break; > - case Opt_logbsize: > - if (match_kstrtoint(args, 10, &mp->m_logbsize)) > - return -EINVAL; > - break; > - case Opt_logdev: > - kfree(mp->m_logname); > - mp->m_logname = match_strdup(args); > - if (!mp->m_logname) > - return -ENOMEM; > - break; > - case Opt_rtdev: > - kfree(mp->m_rtname); > - mp->m_rtname = match_strdup(args); > - if (!mp->m_rtname) > - return -ENOMEM; > - break; > - case Opt_allocsize: > - if (match_kstrtoint(args, 10, &iosize)) > - return -EINVAL; > - iosizelog = ffs(iosize) - 1; > - break; > - case Opt_grpid: > - case Opt_bsdgroups: > - mp->m_flags |= XFS_MOUNT_GRPID; > - break; > - case Opt_nogrpid: > - case Opt_sysvgroups: > - mp->m_flags &= ~XFS_MOUNT_GRPID; > - break; > - case Opt_wsync: > - mp->m_flags |= XFS_MOUNT_WSYNC; > - break; > - case Opt_norecovery: > - mp->m_flags |= XFS_MOUNT_NORECOVERY; > - break; > - case Opt_noalign: > - mp->m_flags |= XFS_MOUNT_NOALIGN; > - break; > - case Opt_swalloc: > - mp->m_flags |= XFS_MOUNT_SWALLOC; > - break; > - case Opt_sunit: > - if (match_int(args, &dsunit)) > - return -EINVAL; > - break; > - case Opt_swidth: > - if (match_int(args, &dswidth)) > - return -EINVAL; > - break; > - case Opt_inode32: > - mp->m_flags |= XFS_MOUNT_SMALL_INUMS; > - break; > - case Opt_inode64: > - mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS; > - break; > - case Opt_nouuid: > - mp->m_flags |= XFS_MOUNT_NOUUID; > - break; > - case Opt_ikeep: > - mp->m_flags |= XFS_MOUNT_IKEEP; > - break; > - case Opt_noikeep: > - mp->m_flags &= ~XFS_MOUNT_IKEEP; > - break; > - case Opt_largeio: > - mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE; > - break; > - case Opt_nolargeio: > - mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; > - break; > - case Opt_attr2: > - mp->m_flags |= XFS_MOUNT_ATTR2; > - break; > - case Opt_noattr2: > - mp->m_flags &= ~XFS_MOUNT_ATTR2; > - mp->m_flags |= XFS_MOUNT_NOATTR2; > - break; > - case Opt_filestreams: > - mp->m_flags |= XFS_MOUNT_FILESTREAMS; > - break; > - case Opt_noquota: > - mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT; > - mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD; > - mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE; > - break; > - case Opt_quota: > - case Opt_uquota: > - case Opt_usrquota: > - mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE | > - XFS_UQUOTA_ENFD); > - break; > - case Opt_qnoenforce: > - case Opt_uqnoenforce: > - mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); > - mp->m_qflags &= ~XFS_UQUOTA_ENFD; > - break; > - case Opt_pquota: > - case Opt_prjquota: > - mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE | > - XFS_PQUOTA_ENFD); > - break; > - case Opt_pqnoenforce: > - mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); > - mp->m_qflags &= ~XFS_PQUOTA_ENFD; > - break; > - case Opt_gquota: > - case Opt_grpquota: > - mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE | > - XFS_GQUOTA_ENFD); > - break; > - case Opt_gqnoenforce: > - mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); > - mp->m_qflags &= ~XFS_GQUOTA_ENFD; > - break; > - case Opt_discard: > - mp->m_flags |= XFS_MOUNT_DISCARD; > - break; > - case Opt_nodiscard: > - mp->m_flags &= ~XFS_MOUNT_DISCARD; > - break; > -#ifdef CONFIG_FS_DAX > - case Opt_dax: > - mp->m_flags |= XFS_MOUNT_DAX; > - break; > -#endif > - default: > - xfs_warn(mp, "unknown mount option [%s].", p); > - return -EINVAL; > - } > + ret = xfs_fc_parse_param(token, p, args, mp, &dsunit, &dswidth, > + &iosizelog); > + if (ret) > + return ret; > } > > /* >