Skip to content

Commit ffdcc3b

Browse files
author
Darrick J. Wong
committed
xfs: refactor name/value iovec validation in xlog_recover_attri_commit_pass2
Hoist the code that checks the attr name and value iovecs into separate helpers so that we can add more callsites for the new parent pointer attr intent items. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 5085542 commit ffdcc3b

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

fs/xfs/xfs_attr_item.c

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,46 @@ const struct xfs_defer_op_type xfs_attr_defer_type = {
734734
.relog_intent = xfs_attr_relog_intent,
735735
};
736736

737+
static inline void *
738+
xfs_attri_validate_name_iovec(
739+
struct xfs_mount *mp,
740+
struct xfs_attri_log_format *attri_formatp,
741+
const struct xfs_log_iovec *iovec,
742+
unsigned int name_len)
743+
{
744+
if (iovec->i_len != xlog_calc_iovec_len(name_len)) {
745+
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
746+
attri_formatp, sizeof(*attri_formatp));
747+
return NULL;
748+
}
749+
750+
if (!xfs_attr_namecheck(iovec->i_addr, name_len)) {
751+
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
752+
attri_formatp, sizeof(*attri_formatp));
753+
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
754+
iovec->i_addr, iovec->i_len);
755+
return NULL;
756+
}
757+
758+
return iovec->i_addr;
759+
}
760+
761+
static inline void *
762+
xfs_attri_validate_value_iovec(
763+
struct xfs_mount *mp,
764+
struct xfs_attri_log_format *attri_formatp,
765+
const struct xfs_log_iovec *iovec,
766+
unsigned int value_len)
767+
{
768+
if (iovec->i_len != xlog_calc_iovec_len(value_len)) {
769+
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
770+
attri_formatp, sizeof(*attri_formatp));
771+
return NULL;
772+
}
773+
774+
return iovec->i_addr;
775+
}
776+
737777
STATIC int
738778
xlog_recover_attri_commit_pass2(
739779
struct xlog *log,
@@ -798,30 +838,18 @@ xlog_recover_attri_commit_pass2(
798838
i++;
799839

800840
/* Validate the attr name */
801-
if (item->ri_buf[i].i_len != xlog_calc_iovec_len(name_len)) {
802-
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
803-
attri_formatp, len);
804-
return -EFSCORRUPTED;
805-
}
806-
807-
attr_name = item->ri_buf[i].i_addr;
808-
if (!xfs_attr_namecheck(attr_name, name_len)) {
809-
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
810-
attri_formatp, len);
841+
attr_name = xfs_attri_validate_name_iovec(mp, attri_formatp,
842+
&item->ri_buf[i], name_len);
843+
if (!attr_name)
811844
return -EFSCORRUPTED;
812-
}
813845
i++;
814846

815847
/* Validate the attr value, if present */
816848
if (value_len != 0) {
817-
if (item->ri_buf[i].i_len != xlog_calc_iovec_len(value_len)) {
818-
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
819-
item->ri_buf[0].i_addr,
820-
item->ri_buf[0].i_len);
849+
attr_value = xfs_attri_validate_value_iovec(mp, attri_formatp,
850+
&item->ri_buf[i], value_len);
851+
if (!attr_value)
821852
return -EFSCORRUPTED;
822-
}
823-
824-
attr_value = item->ri_buf[i].i_addr;
825853
i++;
826854
}
827855

0 commit comments

Comments
 (0)