@@ -392,12 +392,22 @@ xfs_attr_rmtval_get(
int blkcnt = args->rmtblkcnt;
int i;
int offset = 0;
+ int flags = 0;
+ void *addr;
trace_xfs_attr_rmtval_get(args);
ASSERT(args->valuelen != 0);
ASSERT(args->rmtvaluelen == args->valuelen);
+ /*
+ * We also check for _OP_BUFFER as we want to trigger on
+ * verity blocks only, not on verity_descriptor
+ */
+ if (args->attr_filter & XFS_ATTR_VERITY &&
+ args->op_flags & XFS_DA_OP_BUFFER)
+ flags = XBF_DOUBLE_ALLOC;
+
valuelen = args->rmtvaluelen;
while (valuelen > 0) {
nmap = ATTR_RMTVALUE_MAPSIZE;
@@ -417,10 +427,21 @@ xfs_attr_rmtval_get(
dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
error = xfs_buf_read(mp->m_ddev_targp, dblkno, dblkcnt,
- 0, &bp, &xfs_attr3_rmt_buf_ops);
+ flags, &bp, &xfs_attr3_rmt_buf_ops);
if (error)
return error;
+ /*
+ * For fs-verity we allocated more space. That space is
+ * filled with the same xattr data but without leaf
+ * headers. Point args->value to that data
+ */
+ if (flags & XBF_DOUBLE_ALLOC) {
+ addr = xfs_buf_offset(bp, BBTOB(bp->b_length));
+ args->value = addr;
+ dst = addr;
+ }
+
error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino,
&offset, &valuelen,
&dst);
@@ -521,7 +542,8 @@ xfs_attr_rmtval_set_value(
dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
- error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0, &bp);
+ error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt,
+ XBF_DOUBLE_ALLOC, &bp);
if (error)
return error;
bp->b_ops = &xfs_attr3_rmt_buf_ops;
@@ -328,6 +328,9 @@ xfs_buf_alloc_kmem(
xfs_km_flags_t kmflag_mask = KM_NOFS;
size_t size = BBTOB(bp->b_length);
+ if (flags & XBF_DOUBLE_ALLOC)
+ size *= 2;
+
/* Assure zeroed buffer for non-read cases. */
if (!(flags & XBF_READ))
kmflag_mask |= KM_ZERO;
@@ -358,6 +361,7 @@ xfs_buf_alloc_pages(
{
gfp_t gfp_mask = __GFP_NOWARN;
long filled = 0;
+ int mul = (bp->b_flags & XBF_DOUBLE_ALLOC) ? 2 : 1;
if (flags & XBF_READ_AHEAD)
gfp_mask |= __GFP_NORETRY;
@@ -365,7 +369,7 @@ xfs_buf_alloc_pages(
gfp_mask |= GFP_NOFS;
/* Make sure that we have a page list */
- bp->b_page_count = DIV_ROUND_UP(BBTOB(bp->b_length), PAGE_SIZE);
+ bp->b_page_count = DIV_ROUND_UP(BBTOB(bp->b_length*mul), PAGE_SIZE);
if (bp->b_page_count <= XB_PAGES) {
bp->b_pages = bp->b_page_array;
} else {
@@ -33,6 +33,7 @@ struct xfs_buf;
#define XBF_STALE (1u << 6) /* buffer has been staled, do not find it */
#define XBF_WRITE_FAIL (1u << 7) /* async writes have failed on this buffer */
#define XBF_VERITY_SEEN (1u << 8) /* buffer was processed by fs-verity */
+#define XBF_DOUBLE_ALLOC (1u << 9) /* double allocated space */
/* buffer type flags for write callbacks */
#define _XBF_INODES (1u << 16)/* inode buffer */
@@ -67,6 +68,7 @@ typedef unsigned int xfs_buf_flags_t;
{ XBF_STALE, "STALE" }, \
{ XBF_WRITE_FAIL, "WRITE_FAIL" }, \
{ XBF_VERITY_SEEN, "VERITY_SEEN" }, \
+ { XBF_DOUBLE_ALLOC, "DOUBLE_ALLOC" }, \
{ _XBF_INODES, "INODES" }, \
{ _XBF_DQUOTS, "DQUOTS" }, \
{ _XBF_LOGRECOVERY, "LOG_RECOVERY" }, \
For fs-verity integration, XFS needs to supply kaddr'es of Merkle tree blocks to fs-verity core and track which blocks are already verified. One way to track verified status is to set xfs_buf flag (previously added XBF_VERITY_SEEN). When xfs_buf is evicted from memory we loose verified status. Otherwise, fs-verity hits the xfs_buf which is still in cache and contains already verified blocks. However, the leaf blocks which are read to the xfs_buf contains leaf headers. xfs_attr_get() allocates new pages and copies out the data without header. Those newly allocated pages with extended attribute data are not attached to the buffer anymore. Add new XBF_DOUBLE_ALLOC which makes xfs_buf allocates x2 memory for the buffer. Additional memory will be used for a copy of the attribute data but without any headers. Also, make xfs_attr_rmtval_get() to copy data to the buffer itself if XFS asked for fs-verity block. Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com> --- fs/xfs/libxfs/xfs_attr_remote.c | 26 ++++++++++++++++++++++++-- fs/xfs/xfs_buf.c | 6 +++++- fs/xfs/xfs_buf.h | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-)