From patchwork Tue Aug 20 20:21:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11104589 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E34F14F7 for ; Tue, 20 Aug 2019 20:21:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1ECF822DA7 for ; Tue, 20 Aug 2019 20:21:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729950AbfHTUVi (ORCPT ); Tue, 20 Aug 2019 16:21:38 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:58952 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727358AbfHTUVi (ORCPT ); Tue, 20 Aug 2019 16:21:38 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIuDQ157962; Tue, 20 Aug 2019 20:21:36 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2uea7qrxdn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:36 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIJZw165000; Tue, 20 Aug 2019 20:21:35 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2ugj7p4h8y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:35 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x7KKLXP2015813; Tue, 20 Aug 2019 20:21:34 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Aug 2019 13:21:33 -0700 Subject: [PATCH 1/4] xfs_restore: refactor open-coded file creation code From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 20 Aug 2019 13:21:32 -0700 Message-ID: <156633249273.1207741.14136110846397501551.stgit@magnolia> In-Reply-To: <156633248668.1207741.376678690204909405.stgit@magnolia> References: <156633248668.1207741.376678690204909405.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Create a helper to unlink, recreate, and reserve space in a file so that we don't have two open-coded versions. We lose the broken ALLOCSP code since it never worked anyway. Signed-off-by: Darrick J. Wong --- restore/dirattr.c | 97 ++++++++++++++++++----------------------------------- restore/dirattr.h | 2 + restore/namreg.c | 70 +++----------------------------------- 3 files changed, 41 insertions(+), 128 deletions(-) diff --git a/restore/dirattr.c b/restore/dirattr.c index 806f282..5cd22a8 100644 --- a/restore/dirattr.c +++ b/restore/dirattr.c @@ -55,6 +55,37 @@ #include "openutil.h" #include "mmap.h" +/* Create a file, try to reserve space for it, and return the fd. */ +int +create_filled_file( + const char *pathname, + off64_t size) +{ + struct flock64 fl = { + .l_len = size, + }; + int fd; + int ret; + + (void)unlink(pathname); + + fd = open(pathname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + if (fd < 0) + return fd; + + ret = ioctl(fd, XFS_IOC_RESVSP64, &fl); + if (ret && errno != ENOTTY) + mlog(MLOG_VERBOSE | MLOG_NOTE, +_("attempt to reserve %lld bytes for %s using %s failed: %s (%d)\n"), + size, pathname, "XFS_IOC_RESVSP64", + strerror(errno), errno); + if (ret == 0) + goto done; + +done: + return fd; +} + /* structure definitions used locally ****************************************/ /* node handle limits @@ -238,13 +269,8 @@ dirattr_init(char *hkdir, bool_t resume, uint64_t dircnt) return BOOL_FALSE; } } else { - /* create the dirattr file, first unlinking any older version - * laying around - */ - (void)unlink(dtp->dt_pathname); - dtp->dt_fd = open(dtp->dt_pathname, - O_RDWR | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR); + dtp->dt_fd = create_filled_file(dtp->dt_pathname, + DIRATTR_PERS_SZ + (dircnt * sizeof(struct dirattr))); if (dtp->dt_fd < 0) { mlog(MLOG_NORMAL | MLOG_ERROR, _( "could not create directory attributes file %s: " @@ -253,63 +279,6 @@ dirattr_init(char *hkdir, bool_t resume, uint64_t dircnt) strerror(errno)); return BOOL_FALSE; } - - /* reserve space for the backing store. try to use RESVSP64. - * if doesn't work, try ALLOCSP64. the former is faster, as - * it does not zero the space. - */ - { - bool_t successpr; - unsigned int ioctlcmd; - int loglevel; - size_t trycnt; - - for (trycnt = 0, - successpr = BOOL_FALSE, - ioctlcmd = XFS_IOC_RESVSP64, - loglevel = MLOG_VERBOSE - ; - !successpr && trycnt < 2 - ; - trycnt++, - ioctlcmd = XFS_IOC_ALLOCSP64, - loglevel = max(MLOG_NORMAL, loglevel - 1)) { - off64_t initsz; - struct flock64 flock64; - int rval; - - if (!ioctlcmd) { - continue; - } - - initsz = (off64_t)DIRATTR_PERS_SZ - + - ((off64_t)dircnt * sizeof(dirattr_t)); - flock64.l_whence = 0; - flock64.l_start = 0; - flock64.l_len = initsz; - rval = ioctl(dtp->dt_fd, ioctlcmd, &flock64); - if (rval) { - if (errno != ENOTTY) { - mlog(loglevel | MLOG_NOTE, _( - "attempt to reserve %lld bytes for %s " - "using %s " - "failed: %s (%d)\n"), - initsz, - dtp->dt_pathname, - ioctlcmd == XFS_IOC_RESVSP64 - ? - "XFS_IOC_RESVSP64" - : - "XFS_IOC_ALLOCSP64", - strerror(errno), - errno); - } - } else { - successpr = BOOL_TRUE; - } - } - } } /* mmap the persistent descriptor diff --git a/restore/dirattr.h b/restore/dirattr.h index 232822e..cdfa4fc 100644 --- a/restore/dirattr.h +++ b/restore/dirattr.h @@ -88,4 +88,6 @@ extern bool_t dirattr_cb_extattr(dah_t dah, extattrhdr_t *ahdrp, void *ctxp); +int create_filled_file(const char *pathname, off64_t size); + #endif /* DIRATTR_H */ diff --git a/restore/namreg.c b/restore/namreg.c index fe159e4..594e325 100644 --- a/restore/namreg.c +++ b/restore/namreg.c @@ -37,6 +37,10 @@ #include "namreg.h" #include "openutil.h" #include "mmap.h" +#include "global.h" +#include "content.h" +#include "content_inode.h" +#include "dirattr.h" /* structure definitions used locally ****************************************/ @@ -153,13 +157,8 @@ namreg_init(char *hkdir, bool_t resume, uint64_t inocnt) return BOOL_FALSE; } } else { - /* create the namreg file, first unlinking any older version - * laying around - */ - (void)unlink(ntp->nt_pathname); - ntp->nt_fd = open(ntp->nt_pathname, - O_RDWR | O_CREAT | O_EXCL, - S_IRUSR | S_IWUSR); + ntp->nt_fd = create_filled_file(ntp->nt_pathname, + NAMREG_PERS_SZ + (inocnt * NAMREG_AVGLEN)); if (ntp->nt_fd < 0) { mlog(MLOG_NORMAL | MLOG_ERROR, _( "could not create name registry file %s: " @@ -168,63 +167,6 @@ namreg_init(char *hkdir, bool_t resume, uint64_t inocnt) strerror(errno)); return BOOL_FALSE; } - - /* reserve space for the backing store. try to use RESVSP64. - * if doesn't work, try ALLOCSP64. the former is faster, as - * it does not zero the space. - */ - { - bool_t successpr; - unsigned int ioctlcmd; - int loglevel; - size_t trycnt; - - for (trycnt = 0, - successpr = BOOL_FALSE, - ioctlcmd = XFS_IOC_RESVSP64, - loglevel = MLOG_VERBOSE - ; - !successpr && trycnt < 2 - ; - trycnt++, - ioctlcmd = XFS_IOC_ALLOCSP64, - loglevel = max(MLOG_NORMAL, loglevel - 1)) { - off64_t initsz; - struct flock64 flock64; - int rval; - - if (!ioctlcmd) { - continue; - } - - initsz = (off64_t)NAMREG_PERS_SZ - + - ((off64_t)inocnt * NAMREG_AVGLEN); - flock64.l_whence = 0; - flock64.l_start = 0; - flock64.l_len = initsz; - rval = ioctl(ntp->nt_fd, ioctlcmd, &flock64); - if (rval) { - if (errno != ENOTTY) { - mlog(loglevel | MLOG_NOTE, _( - "attempt to reserve %lld bytes for %s " - "using %s " - "failed: %s (%d)\n"), - initsz, - ntp->nt_pathname, - ioctlcmd == XFS_IOC_RESVSP64 - ? - "XFS_IOC_RESVSP64" - : - "XFS_IOC_ALLOCSP64", - strerror(errno), - errno); - } - } else { - successpr = BOOL_TRUE; - } - } - } } /* mmap the persistent descriptor From patchwork Tue Aug 20 20:21:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11104591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9349D14F7 for ; Tue, 20 Aug 2019 20:21:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71D2E22DA9 for ; Tue, 20 Aug 2019 20:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730006AbfHTUVn (ORCPT ); Tue, 20 Aug 2019 16:21:43 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:59012 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727358AbfHTUVm (ORCPT ); Tue, 20 Aug 2019 16:21:42 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIvww158005; Tue, 20 Aug 2019 20:21:41 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2uea7qrxe2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:41 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIK6k165050; Tue, 20 Aug 2019 20:21:40 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2ugj7p4haq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:40 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x7KKLdAf012772; Tue, 20 Aug 2019 20:21:39 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Aug 2019 13:21:39 -0700 Subject: [PATCH 2/4] xfs_restore: check return value From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 20 Aug 2019 13:21:38 -0700 Message-ID: <156633249881.1207741.10808274938868121155.stgit@magnolia> In-Reply-To: <156633248668.1207741.376678690204909405.stgit@magnolia> References: <156633248668.1207741.376678690204909405.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=961 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Check the return value of the unlink call when creating a new file. Signed-off-by: Darrick J. Wong --- restore/dirattr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/restore/dirattr.c b/restore/dirattr.c index 5cd22a8..ed7e0b4 100644 --- a/restore/dirattr.c +++ b/restore/dirattr.c @@ -67,7 +67,9 @@ create_filled_file( int fd; int ret; - (void)unlink(pathname); + ret = unlink(pathname); + if (ret && errno != ENOENT) + return ret; fd = open(pathname, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); if (fd < 0) From patchwork Tue Aug 20 20:21:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11104593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 563BB13B1 for ; Tue, 20 Aug 2019 20:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DA4722D6D for ; Tue, 20 Aug 2019 20:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730092AbfHTUVy (ORCPT ); Tue, 20 Aug 2019 16:21:54 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:34308 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730756AbfHTUVy (ORCPT ); Tue, 20 Aug 2019 16:21:54 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIw0S143462; Tue, 20 Aug 2019 20:21:53 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2ue90th3tk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:53 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIZTa134742; Tue, 20 Aug 2019 20:21:52 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2ug1g9rag8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:52 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x7KKLplD028762; Tue, 20 Aug 2019 20:21:51 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Aug 2019 13:21:51 -0700 Subject: [PATCH 3/4] xfs_restore: fix unsupported ioctl detection From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 20 Aug 2019 13:21:44 -0700 Message-ID: <156633250490.1207741.2481254459114902054.stgit@magnolia> In-Reply-To: <156633248668.1207741.376678690204909405.stgit@magnolia> References: <156633248668.1207741.376678690204909405.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=946 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Linux ioctls can return ENOTTY or EOPNOTSUPP, so filter both of them when logging reservation failure. Signed-off-by: Darrick J. Wong --- restore/dirattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/restore/dirattr.c b/restore/dirattr.c index ed7e0b4..267bef0 100644 --- a/restore/dirattr.c +++ b/restore/dirattr.c @@ -76,7 +76,7 @@ create_filled_file( return fd; ret = ioctl(fd, XFS_IOC_RESVSP64, &fl); - if (ret && errno != ENOTTY) + if (ret && (errno != EOPNOTSUPP && errno != ENOTTY)) mlog(MLOG_VERBOSE | MLOG_NOTE, _("attempt to reserve %lld bytes for %s using %s failed: %s (%d)\n"), size, pathname, "XFS_IOC_RESVSP64", From patchwork Tue Aug 20 20:21:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11104595 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76F5613B1 for ; Tue, 20 Aug 2019 20:22:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F78B22DA9 for ; Tue, 20 Aug 2019 20:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730806AbfHTUWB (ORCPT ); Tue, 20 Aug 2019 16:22:01 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46932 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730804AbfHTUWA (ORCPT ); Tue, 20 Aug 2019 16:22:00 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIv8R172542; Tue, 20 Aug 2019 20:21:58 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2ue9hpgxmv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:58 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7KKIK3D165108; Tue, 20 Aug 2019 20:21:58 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2ugj7p4hgr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2019 20:21:58 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x7KKLvZE028835; Tue, 20 Aug 2019 20:21:57 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Aug 2019 13:21:57 -0700 Subject: [PATCH 4/4] xfs_restore: support fallocate when reserving space for a file From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 20 Aug 2019 13:21:56 -0700 Message-ID: <156633251670.1207741.14528791952409305250.stgit@magnolia> In-Reply-To: <156633248668.1207741.376678690204909405.stgit@magnolia> References: <156633248668.1207741.376678690204909405.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=9 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9355 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=9 phishscore=0 bulkscore=0 spamscore=0 clxscore=1034 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908200181 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Update the file creation helper to try fallocate when restoring a filesystem before it tries RESVSP. Signed-off-by: Darrick J. Wong --- configure.ac | 2 ++ include/builddefs.in | 1 + m4/Makefile | 1 + m4/package_libcdev.m4 | 15 +++++++++++++++ restore/Makefile | 4 ++++ restore/dirattr.c | 11 +++++++++++ 6 files changed, 34 insertions(+) create mode 100644 m4/package_libcdev.m4 diff --git a/configure.ac b/configure.ac index a77054c..73dedd7 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,8 @@ AC_PACKAGE_NEED_ATTRIBUTES_H AC_PACKAGE_NEED_ATTRIBUTES_MACROS AC_PACKAGE_NEED_ATTRGET_LIBATTR +AC_HAVE_FALLOCATE + AC_MANUAL_FORMAT AC_CONFIG_FILES([include/builddefs]) diff --git a/include/builddefs.in b/include/builddefs.in index 269c928..1c7e12f 100644 --- a/include/builddefs.in +++ b/include/builddefs.in @@ -69,6 +69,7 @@ ENABLE_SHARED = @enable_shared@ ENABLE_GETTEXT = @enable_gettext@ HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@ +HAVE_FALLOCATE = @have_fallocate@ GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall # -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl diff --git a/m4/Makefile b/m4/Makefile index 9a35056..ae452f7 100644 --- a/m4/Makefile +++ b/m4/Makefile @@ -16,6 +16,7 @@ LSRCFILES = \ manual_format.m4 \ package_attrdev.m4 \ package_globals.m4 \ + package_libcdev.m4 \ package_ncurses.m4 \ package_pthread.m4 \ package_utilies.m4 \ diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4 new file mode 100644 index 0000000..050f82c --- /dev/null +++ b/m4/package_libcdev.m4 @@ -0,0 +1,15 @@ +# +# Check if we have a fallocate libc call (Linux) +# +AC_DEFUN([AC_HAVE_FALLOCATE], + [ AC_MSG_CHECKING([for fallocate]) + AC_TRY_LINK([ +#include +#include + ], [ + fallocate(0, 0, 0, 0); + ], have_fallocate=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) + AC_SUBST(have_fallocate) + ]) diff --git a/restore/Makefile b/restore/Makefile index 20c870a..ac3f8c8 100644 --- a/restore/Makefile +++ b/restore/Makefile @@ -102,6 +102,10 @@ LTDEPENDENCIES = $(LIBRMT) LCFLAGS = -DRESTORE +ifeq ($(HAVE_FALLOCATE),yes) +LCFLAGS += -DHAVE_FALLOCATE +endif + default: depend $(LTCOMMAND) include $(BUILDRULES) diff --git a/restore/dirattr.c b/restore/dirattr.c index 267bef0..15a16d1 100644 --- a/restore/dirattr.c +++ b/restore/dirattr.c @@ -75,6 +75,17 @@ create_filled_file( if (fd < 0) return fd; +#ifdef HAVE_FALLOCATE + ret = fallocate(fd, 0, 0, size); + if (ret && (errno != EOPNOTSUPP && errno != ENOTTY)) + mlog(MLOG_VERBOSE | MLOG_NOTE, +_("attempt to reserve %lld bytes for %s using %s failed: %s (%d)\n"), + size, pathname, "fallocate", + strerror(errno), errno); + if (ret == 0) + goto done; +#endif + ret = ioctl(fd, XFS_IOC_RESVSP64, &fl); if (ret && (errno != EOPNOTSUPP && errno != ENOTTY)) mlog(MLOG_VERBOSE | MLOG_NOTE,