[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 2/8] 9pfs: deduplicate iounit code
From: |
Christian Schoenebeck |
Subject: |
[PULL 2/8] 9pfs: deduplicate iounit code |
Date: |
Wed, 27 Oct 2021 15:18:33 +0200 |
Remove redundant code that translates host fileystem's block
size into 9p client (guest side) block size.
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id:
<129bb71d5119e61d335f1e3107e472e4beea223a.1632758315.git.qemu_oss@crudebyte.com>
---
hw/9pfs/9p.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 708b030474..5c57344667 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)
--
2.20.1
- [PULL 0/8] 9p queue 2021-10-27, Christian Schoenebeck, 2021/10/27
- [PULL 1/8] 9pfs: fix wrong I/O block size in Rgetattr, Christian Schoenebeck, 2021/10/27
- [PULL 2/8] 9pfs: deduplicate iounit code,
Christian Schoenebeck <=
- [PULL 3/8] 9pfs: simplify blksize_to_iounit(), Christian Schoenebeck, 2021/10/27
- [PULL 4/8] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/27
- [PULL 5/8] fsdev/p9array.h: check scalar type in P9ARRAY_NEW(), Christian Schoenebeck, 2021/10/27
- [PULL 7/8] 9pfs: make V9fsPath usable via P9Array API, Christian Schoenebeck, 2021/10/27
- [PULL 6/8] 9pfs: make V9fsString usable via P9Array API, Christian Schoenebeck, 2021/10/27
- [PULL 8/8] 9pfs: use P9Array in v9fs_walk(), Christian Schoenebeck, 2021/10/27
- Re: [PULL 0/8] 9p queue 2021-10-27, Christian Schoenebeck, 2021/10/27