From 669ced09b3b6070d478acce51810591b78ab0ccd Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Wed, 22 Sep 2021 15:13:31 +0200 Subject: 9pfs: fix wrong I/O block size in Rgetattr When client sent a 9p Tgetattr request then the wrong I/O block size value was returned by 9p server; instead of host file system's I/O block size it should rather return an I/O block size according to 9p session's 'msize' value, because the value returned to client should be an "optimum" block size for I/O (i.e. to maximize performance), it should not reflect the actual physical block size of the underlying storage media. The I/O block size of a host filesystem is typically 4k, so the value returned was far too low for good 9p I/O performance. This patch adds stat_to_iounit() with a similar approach as the existing get_iounit() function. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Message-Id: --- hw/9pfs/9p.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index c857b31..708b030 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1262,6 +1262,25 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path, #define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */ +static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) +{ + int32_t iounit = 0; + V9fsState *s = pdu->s; + + /* + * iounit should be multiples of st_blksize (host filesystem block size) + * as well as less than (client msize - P9_IOHDRSZ) + */ + if (stbuf->st_blksize) { + iounit = stbuf->st_blksize; + iounit *= (s->msize - P9_IOHDRSZ) / stbuf->st_blksize; + } + if (!iounit) { + iounit = s->msize - P9_IOHDRSZ; + } + return iounit; +} + static int stat_to_v9stat_dotl(V9fsPDU *pdu, const struct stat *stbuf, V9fsStatDotl *v9lstat) { @@ -1273,7 +1292,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; -- cgit v1.1 From b565bccb00afe8b73d529bbc3a38682996dac5c7 Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Mon, 27 Sep 2021 17:45:00 +0200 Subject: 9pfs: deduplicate iounit code Remove redundant code that translates host fileystem's block size into 9p client (guest side) block size. Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Message-Id: <129bb71d5119e61d335f1e3107e472e4beea223a.1632758315.git.qemu_oss@crudebyte.com> --- hw/9pfs/9p.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'hw') diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 708b030..5c57344 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1262,18 +1262,26 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *path, #define P9_STATS_ALL 0x00003fffULL /* Mask for All fields above */ -static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) +/** + * 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 st_blksize (host filesystem block size) + * iounit should be multiples of blksize (host filesystem block size) * as well as less than (client msize - P9_IOHDRSZ) */ - if (stbuf->st_blksize) { - iounit = stbuf->st_blksize; - iounit *= (s->msize - P9_IOHDRSZ) / stbuf->st_blksize; + if (blksize) { + iounit = blksize; + iounit *= (s->msize - P9_IOHDRSZ) / blksize; } if (!iounit) { iounit = s->msize - P9_IOHDRSZ; @@ -1281,6 +1289,11 @@ static int32_t stat_to_iounit(const V9fsPDU *pdu, const struct stat *stbuf) 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) { @@ -1899,23 +1912,9 @@ out_nofid: 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) -- cgit v1.1 From 04a7f9e55e0930b87805f7c97851eea4610e78fc Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Mon, 27 Sep 2021 17:50:36 +0200 Subject: 9pfs: simplify blksize_to_iounit() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use QEMU_ALIGN_DOWN() macro to reduce code and to make it more human readable. Suggested-by: Philippe Mathieu-Daudé Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daudé Message-Id: --- hw/9pfs/9p.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 5c57344..e874899 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1280,8 +1280,7 @@ static int32_t blksize_to_iounit(const V9fsPDU *pdu, int32_t blksize) * as well as less than (client msize - P9_IOHDRSZ) */ if (blksize) { - iounit = blksize; - iounit *= (s->msize - P9_IOHDRSZ) / blksize; + iounit = QEMU_ALIGN_DOWN(s->msize - P9_IOHDRSZ, blksize); } if (!iounit) { iounit = s->msize - P9_IOHDRSZ; -- cgit v1.1 From cc82fde9c7b4b598907914896ee6942fa866258c Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Fri, 1 Oct 2021 16:27:46 +0200 Subject: 9pfs: make V9fsPath usable via P9Array API Signed-off-by: Christian Schoenebeck Message-Id: <79a0ddf8375f6c95f0565ef155a1bf1e9387664f.1633097129.git.qemu_oss@crudebyte.com> --- hw/9pfs/9p.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'hw') diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index e874899..15bb16f 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; -- cgit v1.1 From 7e985780aaab93d2c5be9b62d8d386568dfb071e Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Fri, 1 Oct 2021 16:27:59 +0200 Subject: 9pfs: use P9Array in v9fs_walk() Signed-off-by: Christian Schoenebeck Message-Id: <90c65d1c1ca11c1b434bb981b1fc7966f7711c8f.1633097129.git.qemu_oss@crudebyte.com> --- hw/9pfs/9p.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'hw') diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 15bb16f..15b3f4d 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1738,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; @@ -1765,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) { @@ -1900,14 +1901,6 @@ 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) -- cgit v1.1