From: Haozhong Zhang <haozhong.zhang@intel.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
Xiao Guangrong <guangrong.xiao@gmail.com>,
Stefan Hajnoczi <stefanha@gmail.com>,
Dan Williams <dan.j.williams@intel.com>,
Haozhong Zhang <haozhong.zhang@intel.com>
Subject: [Qemu-devel] [PATCH v2 4/4] util/mmap-alloc: account for DAX device in qemu_fd_getpagesize
Date: Tue, 6 Jun 2017 15:22:29 +0800 [thread overview]
Message-ID: <20170606072229.9302-5-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20170606072229.9302-1-haozhong.zhang@intel.com>
A DAX device may require a page size different than getpagesize().
Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
include/qemu/osdep.h | 10 ++++++++++
util/mmap-alloc.c | 6 ++++++
util/osdep.c | 23 +++++++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 7f26af371e..51aca88f0d 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -479,4 +479,14 @@ pid_t qemu_fork(Error **errp);
*/
bool qemu_fd_is_dev_dax(int fd);
+/**
+ * qemu_get_dev_dax_align:
+ *
+ * Get the suggested alignment of a DAX device descried by @fd.
+ *
+ * Return a non-zero suggested alignment on success; return 0 if @fd
+ * does not describe a DAX device, or if it fails to get alignment
+ * of the DAX device.
+ */
+size_t qemu_get_dev_dax_align(int fd);
#endif
diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 3ec029a9ea..2d8af64b44 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -25,8 +25,14 @@ size_t qemu_fd_getpagesize(int fd)
#ifdef CONFIG_LINUX
struct statfs fs;
int ret;
+ size_t align;
if (fd != -1) {
+ align = qemu_get_dev_dax_align(fd);
+ if (align) {
+ return align;
+ }
+
do {
ret = fstatfs(fd, &fs);
} while (ret != 0 && errno == EINTR);
diff --git a/util/osdep.c b/util/osdep.c
index 02881f96bc..e7837d30b4 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -532,3 +532,26 @@ bool qemu_fd_is_dev_dax(int fd)
return is_dax;
}
+
+size_t qemu_get_dev_dax_align(int fd)
+{
+ size_t align = 0;
+
+#ifdef __linux__
+ char buf[12];
+ ssize_t len;
+
+ if (!qemu_fd_is_dev_dax(fd)) {
+ return 0;
+ }
+ len = qemu_dev_dax_sysfs_read(fd, "device/align", buf, sizeof(buf));
+ if (len <= 0) {
+ return 0;
+ }
+ if (qemu_strtosz(buf, NULL, &align) < 0) {
+ align = 0;
+ }
+#endif /* __linux__ */
+
+ return align;
+}
--
2.11.0
next prev parent reply other threads:[~2017-06-06 7:22 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-06 7:22 [Qemu-devel] [PATCH v2 0/4] nvdimm: fixes for (non-)dax backends Haozhong Zhang
2017-06-06 7:22 ` [Qemu-devel] [PATCH v2 1/4] nvdimm: add a macro for property "label-size" Haozhong Zhang
2017-06-07 15:29 ` Stefan Hajnoczi
2017-06-06 7:22 ` [Qemu-devel] [PATCH v2 2/4] nvdimm: warn if the backend is not a DAX device Haozhong Zhang
2017-06-06 17:59 ` Dan Williams
2017-06-08 1:07 ` Haozhong Zhang
2017-06-07 15:14 ` Stefan Hajnoczi
2017-06-08 1:07 ` Haozhong Zhang
2017-06-08 12:51 ` Michael S. Tsirkin
2017-06-12 3:18 ` Haozhong Zhang
2017-06-12 3:25 ` Michael S. Tsirkin
2017-06-06 7:22 ` [Qemu-devel] [PATCH v2 3/4] nvdimm: add a boolean option "restrict" Haozhong Zhang
2017-06-07 15:27 ` Stefan Hajnoczi
2017-06-08 1:45 ` Haozhong Zhang
2017-06-08 10:19 ` Stefan Hajnoczi
2017-06-08 6:39 ` Haozhong Zhang
2017-06-08 10:18 ` Stefan Hajnoczi
2017-06-08 12:56 ` Michael S. Tsirkin
2017-06-09 9:34 ` Stefan Hajnoczi
2017-06-12 1:18 ` Haozhong Zhang
2017-06-06 7:22 ` Haozhong Zhang [this message]
2017-06-07 15:29 ` [Qemu-devel] [PATCH v2 4/4] util/mmap-alloc: account for DAX device in qemu_fd_getpagesize Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170606072229.9302-5-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=dan.j.williams@intel.com \
--cc=guangrong.xiao@gmail.com \
--cc=imammedo@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).