Skip to contentSkip to conversation

9pfs: move qemu_dirent_dup() from osdep -> 9p-util

PATCH In review Christian Schoenebeck 2 participants 5 messages Mar 1, 2022 – Mar 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 9pfs: move qemu_dirent_dup() from osdep -> 9p-util

Function qemu_dirent_dup() is currently only used by 9pfs server, so move it from project global header osdep.h to 9pfs specific header 9p-util.h.

Based-on: <[email protected]>

---
 hw/9pfs/9p-util.h    | 30 ++++++++++++++++++++++++++++++
 include/qemu/osdep.h | 13 -------------
 util/osdep.c         | 21 ---------------------
 3 files changed, 30 insertions(+), 34 deletions(-)
hw/9pfs/9p-util.h +30 -0
index 1f74d37558..8b92614e6c 100644
@@ -112,6 +112,36 @@ static inline off_t qemu_dirent_off(struct dirent *dent)
 #endif
 }
 
+/**
+ * Duplicate directory entry @dent.
+ *
+ * It is highly recommended to use this function instead of open coding
+ * duplication of @c dirent objects, because the actual @c struct @c dirent
+ * size may be bigger or shorter than @c sizeof(struct dirent) and correct
+ * handling is platform specific (see gitlab issue #841).
+ *
+ * @dent - original directory entry to be duplicated
+ * @returns duplicated directory entry which should be freed with g_free()
+ */
+static inline struct dirent *qemu_dirent_dup(struct dirent *dent)
+{
+    size_t sz = 0;
+#if defined _DIRENT_HAVE_D_RECLEN
+    /* Avoid use of strlen() if platform supports d_reclen. */
+    sz = dent->d_reclen;
+#endif
+    /*
+     * Test sz for zero even if d_reclen is available
+     * because some drivers may set d_reclen to zero.
+     */
+    if (sz == 0) {
+        /* Fallback to the most portable way. */
+        sz = offsetof(struct dirent, d_name) +
+                      strlen(dent->d_name) + 1;
+    }
+    return g_memdup(dent, sz);
+}
+
 /*
  * As long as mknodat is not available on macOS, this workaround
  * using pthread_fchdir_np is needed. qemu_mknodat is defined in
include/qemu/osdep.h +0 -13
index 7bcce3bceb..650ba1aa50 100644
@@ -673,19 +673,6 @@ static inline int platform_does_not_support_system(const char *command)
 }
 #endif /* !HAVE_SYSTEM_FUNCTION */
 
-/**
- * Duplicate directory entry @dent.
- *
- * It is highly recommended to use this function instead of open coding
- * duplication of @c dirent objects, because the actual @c struct @c dirent
- * size may be bigger or shorter than @c sizeof(struct dirent) and correct
- * handling is platform specific (see gitlab issue #841).
- *
- * @dent - original directory entry to be duplicated
- * @returns duplicated directory entry which should be freed with g_free()
- */
-struct dirent *qemu_dirent_dup(struct dirent *dent);
-
 #ifdef __cplusplus
 }
 #endif
util/osdep.c +0 -21
index 723cdcb004..7c4deda6fe 100644
@@ -33,7 +33,6 @@
 extern int madvise(char *, size_t, int);
 #endif
 
-#include <dirent.h>
 #include "qemu-common.h"
 #include "qemu/cutils.h"
 #include "qemu/sockets.h"
@@ -619,23 +618,3 @@ writev(int fd, const struct iovec *iov, int iov_cnt)
     return readv_writev(fd, iov, iov_cnt, true);
 }
 #endif
-
-struct dirent *
-qemu_dirent_dup(struct dirent *dent)
-{
-    size_t sz = 0;
-#if defined _DIRENT_HAVE_D_RECLEN
-    /* Avoid use of strlen() if platform supports d_reclen. */
-    sz = dent->d_reclen;
-#endif
-    /*
-     * Test sz for zero even if d_reclen is available
-     * because some drivers may set d_reclen to zero.
-     */
-    if (sz == 0) {
-        /* Fallback to the most portable way. */
-        sz = offsetof(struct dirent, d_name) +
-                      strlen(dent->d_name) + 1;
-    }
-    return g_memdup(dent, sz);
-}
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Christian Schoenebeck

Function qemu_dirent_dup() is currently only used by 9pfs server, so move it from project global header osdep.h to 9pfs specific header 9p-util.h.

Based-on: <[email protected]>

---
 hw/9pfs/9p-util.h    | 30 ++++++++++++++++++++++++++++++
 include/qemu/osdep.h | 13 -------------
 util/osdep.c         | 21 ---------------------
 3 files changed, 30 insertions(+), 34 deletions(-)
hw/9pfs/9p-util.h +1 -0
index 1f74d37558..8b92614e6c 100644
@@ -112,6 +112,36 @@ static inline off_t qemu_dirent_off(struct dirent *dent)
 #endif
 }
 
+/**

hw/9pfs/9p-util.h static inline off_t qemu_dirent_off(struct dirent *dent) · line 125

Quoted 10 lines
hw/9pfs/9p-util.h +10 -0
+ * Duplicate directory entry @dent.
+ *
+ * It is highly recommended to use this function instead of open coding
+ * duplication of @c dirent objects, because the actual @c struct @c dirent
+ * size may be bigger or shorter than @c sizeof(struct dirent) and correct
+ * handling is platform specific (see gitlab issue #841).
+ *
+ * @dent - original directory entry to be duplicated
+ * @returns duplicated directory entry which should be freed with g_free()
+ */

since it's just code movement, but those "@c"s look a bit weird:
are they really valid kerneldoc comment markup?

thanks
-- PMM

#2 lore raw
Quoted 42 lines · On Dienstag, 1. März 2022 22:59:43 CET Peter Maydell wrote:

On Tue, 1 Mar 2022 at 20:47, Christian Schoenebeck

Quoted 30 lines · <[email protected]> wrote:

Function qemu_dirent_dup() is currently only used by 9pfs server, so move it from project global header osdep.h to 9pfs specific header 9p-util.h.

Link:
https://lore.kernel.org/qemu-devel/CAFEAcA_=HAUNomKD2wurSVaAHa5mrk22A1oHK
[email protected]/ Based-on:
<[email protected]>

---

 hw/9pfs/9p-util.h    | 30 ++++++++++++++++++++++++++++++
 include/qemu/osdep.h | 13 -------------
 util/osdep.c         | 21 ---------------------
 3 files changed, 30 insertions(+), 34 deletions(-)
hw/9pfs/9p-util.h +5 -0
index 1f74d37558..8b92614e6c 100644
@@ -112,6 +112,36 @@ static inline off_t qemu_dirent_off(struct dirent
 *dent)> 
 #endif
 }
 
+/**
+ * Duplicate directory entry @dent.
+ *
+ * It is highly recommended to use this function instead of open coding
+ * duplication of @c dirent objects, because the actual @c struct @c
 dirent + * size may be bigger or shorter than @c sizeof(struct dirent)
Quoted 6 lines

and correct + * handling is platform specific (see gitlab issue #841).
+ *
+ * @dent - original directory entry to be duplicated
+ * @returns duplicated directory entry which should be freed with g_free()
+ */

Quoted 5 lines

since it's just code movement, but those "@c"s look a bit weird:
are they really valid kerneldoc comment markup?

thanks
-- PMM

You are right, that's Doxygen format, not kerneldoc format.

If you don't mind I send a separate, subsequent patch that just wipes the "@c"s away, and leave this patch as-is (as this one is pure refactoring).

Alternatively I could replace the "@c"s by kerneldoc's solution which apparently is "::foo" I think ("foo" being the inlined C code).

Best regards,
Christian Schoenebeck

#3 lore raw
Quoted 17 lines · Christian Schoenebeck
Quoted 15 lines · On Dienstag, 1. März 2022 22:59:43 CET Peter Maydell wrote:

On Tue, 1 Mar 2022 at 20:47, Christian Schoenebeck

Quoted 9 lines · <[email protected]> wrote:

Function qemu_dirent_dup() is currently only used by 9pfs server, so move it from project global header osdep.h to 9pfs specific header 9p-util.h.

Link:
https://lore.kernel.org/qemu-devel/CAFEAcA_=HAUNomKD2wurSVaAHa5mrk22A1oHK
[email protected]/ Based-on:
<[email protected]>

---

Quoted 7 lines
Quoted 2 lines

since it's just code movement, but those "@c"s look a bit weird:
are they really valid kerneldoc comment markup?

You are right, that's Doxygen format, not kerneldoc format.

If you don't mind I send a separate, subsequent patch that just wipes the "@c"s away, and leave this patch as-is (as this one is pure refactoring).

Yes, I agree that should be a separate patch, and just removing the formatting is the simplest approach.

thanks
-- PMM

#4 lore raw
In reply to Christian Schoenebeck
Quoted 7 lines · On Dienstag, 1. März 2022 21:33:49 CET Christian Schoenebeck wrote:

Function qemu_dirent_dup() is currently only used by 9pfs server, so move it from project global header osdep.h to 9pfs specific header 9p-util.h.

Link:
https://lore.kernel.org/qemu-devel/CAFEAcA_=HAUNomKD2wurSVaAHa5mrk22A1oHKLW
[email protected]/ Based-on:
<[email protected]>

Quoted 6 lines
---
 hw/9pfs/9p-util.h    | 30 ++++++++++++++++++++++++++++++
 include/qemu/osdep.h | 13 -------------
 util/osdep.c         | 21 ---------------------
 3 files changed, 30 insertions(+), 34 deletions(-)

Queued on 9p.next:
https://github.com/cschoenebeck/qemu/commits/9p.next

Thanks!

Best regards,
Christian Schoenebeck