aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2021-10-27 11:45:11 -0700
committerRichard Henderson <richard.henderson@linaro.org>2021-10-27 11:45:18 -0700
commitc52d69e7dbaaed0ffdef8125e79218672c30161d (patch)
treefaf814a00e86fa51c9a8f374055bb3669c808442 /hw
parent5c49c6c241e524b6ba7768de07cab6f2056feb90 (diff)
parent7e985780aaab93d2c5be9b62d8d386568dfb071e (diff)
Merge remote-tracking branch 'remotes/cschoenebeck/tags/pull-9p-20211027' into staging
9pfs: performance fix and cleanup * First patch fixes suboptimal I/O performance on guest due to previously incorrect block size being transmitted to 9p client. * Subsequent patches are cleanup ones intended to reduce code complexity. * remotes/cschoenebeck/tags/pull-9p-20211027: 9pfs: use P9Array in v9fs_walk() 9pfs: make V9fsPath usable via P9Array API 9pfs: make V9fsString usable via P9Array API fsdev/p9array.h: check scalar type in P9ARRAY_NEW() 9pfs: introduce P9Array 9pfs: simplify blksize_to_iounit() 9pfs: deduplicate iounit code 9pfs: fix wrong I/O block size in Rgetattr Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'hw')
-rw-r--r--hw/9pfs/9p.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index c857b31321..15b3f4d385 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -50,6 +50,8 @@ enum {
Oappend = 0x80,
};
+P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
+
static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
{
ssize_t ret;
@@ -1262,6 +1264,37 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path,
#define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */
+/**
+ * Convert host filesystem's block size into an appropriate block size for
+ * 9p client (guest OS side). The value returned suggests an "optimum" block
+ * size for 9p I/O, i.e. to maximize performance.
+ *
+ * @pdu: 9p client request
+ * @blksize: host filesystem's block size
+ */
+static int32_t blksize_to_iounit(const V9fsPDU *pdu, int32_t blksize)
+{
+ int32_t iounit = 0;
+ V9fsState *s = pdu->s;
+
+ /*
+ * iounit should be multiples of blksize (host filesystem block size)
+ * as well as less than (client msize - P9_IOHDRSZ)
+ */
+ if (blksize) {
+ iounit = QEMU_ALIGN_DOWN(s->msize - P9_IOHDRSZ, blksize);
+ }
+ if (!iounit) {
+ iounit = s->msize - P9_IOHDRSZ;
+ }
+ return iounit;
+}
+
+static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf)
+{
+ return blksize_to_iounit(pdu, stbuf->st_blksize);
+}
+
static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
V9fsStatDotl *v9lstat)
{
@@ -1273,7 +1306,7 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf,
v9lstat->st_gid = stbuf->st_gid;
v9lstat->st_rdev = stbuf->st_rdev;
v9lstat->st_size = stbuf->st_size;
- v9lstat->st_blksize = stbuf->st_blksize;
+ v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
v9lstat->st_blocks = stbuf->st_blocks;
v9lstat->st_atime_sec = stbuf->st_atime;
v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
@@ -1705,13 +1738,14 @@ static void coroutine_fn v9fs_walk(void *opaque)
int name_idx;
g_autofree V9fsQID *qids = NULL;
int i, err = 0;
- V9fsPath dpath, path, *pathes = NULL;
+ V9fsPath dpath, path;
+ P9ARRAY_REF(V9fsPath) pathes = NULL;
uint16_t nwnames;
struct stat stbuf, fidst;
g_autofree struct stat *stbufs = NULL;
size_t offset = 7;
int32_t fid, newfid;
- V9fsString *wnames = NULL;
+ P9ARRAY_REF(V9fsString) wnames = NULL;
V9fsFidState *fidp;
V9fsFidState *newfidp = NULL;
V9fsPDU *pdu = opaque;
@@ -1732,10 +1766,10 @@ static void coroutine_fn v9fs_walk(void *opaque)
goto out_nofid;
}
if (nwnames) {
- wnames = g_new0(V9fsString, nwnames);
+ P9ARRAY_NEW(V9fsString, wnames, nwnames);
qids = g_new0(V9fsQID, nwnames);
stbufs = g_new0(struct stat, nwnames);
- pathes = g_new0(V9fsPath, nwnames);
+ P9ARRAY_NEW(V9fsPath, pathes, nwnames);
for (i = 0; i < nwnames; i++) {
err = pdu_unmarshal(pdu, offset, "s", &wnames[i]);
if (err < 0) {
@@ -1867,36 +1901,14 @@ out:
v9fs_path_free(&path);
out_nofid:
pdu_complete(pdu, err);
- if (nwnames && nwnames <= P9_MAXWELEM) {
- for (name_idx = 0; name_idx < nwnames; name_idx++) {
- v9fs_string_free(&wnames[name_idx]);
- v9fs_path_free(&pathes[name_idx]);
- }
- g_free(wnames);
- g_free(pathes);
- }
}
static int32_t coroutine_fn get_iounit(V9fsPDU *pdu, V9fsPath *path)
{
struct statfs stbuf;
- int32_t iounit = 0;
- V9fsState *s = pdu->s;
+ int err = v9fs_co_statfs(pdu, path, &stbuf);
- /*
- * iounit should be multiples of f_bsize (host filesystem block size
- * and as well as less than (client msize - P9_IOHDRSZ))
- */
- if (!v9fs_co_statfs(pdu, path, &stbuf)) {
- if (stbuf.f_bsize) {
- iounit = stbuf.f_bsize;
- iounit *= (s->msize - P9_IOHDRSZ) / stbuf.f_bsize;
- }
- }
- if (!iounit) {
- iounit = s->msize - P9_IOHDRSZ;
- }
- return iounit;
+ return blksize_to_iounit(pdu, (err >= 0) ? stbuf.f_bsize : 0);
}
static void coroutine_fn v9fs_open(void *opaque)