hw/9pfs: add xattr count query interface to fs synth driver
Add a synthetic "/stat/xattr_count" file path that, if being read by 9p client, returns the 9p server internal xattr FID counter to client. This allows to test and verify that the xattr FID limit is being enforced correctly. Link: https://lore.kernel.org/qemu-devel/357c20fc244c04dcbd36b13aa20a5c9b2034e9f0.1781361555.git.qemu_oss@crudebyte.com Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Christian Schoenebeck committed
Jun 13, 2026 at 16:55 UTC
7e42d569a68aec6b0b6f1f068328c5c4ff20bc72
1 file changed
+26
hw/9pfs/9p-synth.c
+26
@@ -565,6 +565,19 @@ static ssize_t v9fs_synth_qtest_flush_write(void *buf, int len, off_t offset,
565
return 1;
566
}
567
568
+/* transmits internal xattr counter to client */
569
+static ssize_t v9fs_synth_read_xattr_count(void *buf, int len, off_t offset,
570
+ void *arg)
571
+{
572
+ FsContext *ctx = arg;
573
+ size_t local_count = ctx->xattr_fid_count;
574
+ if (len < (int)sizeof(size_t)) {
575
+ return -ENOSPC;
576
+ }
577
+ memcpy(buf, &local_count, sizeof(size_t));
578
+ return sizeof(size_t);
579
+}
580
+
581
static int synth_init(FsContext *ctx, Error **errp)
582
{
583
QLIST_INIT(&synth_root.child);
@@ -626,6 +639,19 @@ static int synth_init(FsContext *ctx, Error **errp)
639
g_free(name);
640
}
641
}
642
+
643
+ /* Directory for internal statistic queries */
644
+ {
645
+ V9fsSynthNode *stat_dir = NULL;
646
+ ret = qemu_v9fs_synth_mkdir(NULL, 0755, "stat", &stat_dir);
647
+ assert(!ret);
648
+
649
+ /* File for internal xattr count query */
650
+ ret = qemu_v9fs_synth_add_file(stat_dir, 0444, "xattr_count",
651
+ v9fs_synth_read_xattr_count,
652
+ NULL, ctx);
653
+ assert(!ret);
654
+ }
655
}
656
657
return 0;