From nobody Wed Nov 5 17:50:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496733993112962.8244123425064; Tue, 6 Jun 2017 00:26:33 -0700 (PDT) Received: from localhost ([::1]:36577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dI8sp-0003aj-Ts for importer@patchew.org; Tue, 06 Jun 2017 03:26:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dI8pM-0000nD-Ub for qemu-devel@nongnu.org; Tue, 06 Jun 2017 03:22:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dI8pL-0005NA-Se for qemu-devel@nongnu.org; Tue, 06 Jun 2017 03:22:56 -0400 Received: from mga03.intel.com ([134.134.136.65]:58638) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dI8pL-0005K6-Jx for qemu-devel@nongnu.org; Tue, 06 Jun 2017 03:22:55 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2017 00:22:55 -0700 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.149]) by fmsmga006.fm.intel.com with ESMTP; 06 Jun 2017 00:22:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,305,1493708400"; d="scan'208";a="111383321" From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 15:22:29 +0800 Message-Id: <20170606072229.9302-5-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170606072229.9302-1-haozhong.zhang@intel.com> References: <20170606072229.9302-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 4/4] util/mmap-alloc: account for DAX device in qemu_fd_getpagesize X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Haozhong Zhang , "Michael S. Tsirkin" , Stefan Hajnoczi , Xiao Guangrong , Igor Mammedov , Dan Williams Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A DAX device may require a page size different than getpagesize(). Signed-off-by: Haozhong Zhang Reviewed-by: Stefan Hajnoczi --- 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); =20 +/** + * 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; =20 if (fd !=3D -1) { + align =3D qemu_get_dev_dax_align(fd); + if (align) { + return align; + } + do { ret =3D fstatfs(fd, &fs); } while (ret !=3D 0 && errno =3D=3D 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) =20 return is_dax; } + +size_t qemu_get_dev_dax_align(int fd) +{ + size_t align =3D 0; + +#ifdef __linux__ + char buf[12]; + ssize_t len; + + if (!qemu_fd_is_dev_dax(fd)) { + return 0; + } + len =3D qemu_dev_dax_sysfs_read(fd, "device/align", buf, sizeof(buf)); + if (len <=3D 0) { + return 0; + } + if (qemu_strtosz(buf, NULL, &align) < 0) { + align =3D 0; + } +#endif /* __linux__ */ + + return align; +} --=20 2.11.0