From patchwork Tue Nov 3 02:33:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11875775 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 4532E6A2 for ; Tue, 3 Nov 2020 02:34:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E13922275 for ; Tue, 3 Nov 2020 02:34:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dKHeDLb+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726026AbgKCCeH (ORCPT ); Mon, 2 Nov 2020 21:34:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36108 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgKCCeH (ORCPT ); Mon, 2 Nov 2020 21:34:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604370845; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=VR9Xpzs08VUXpHhn7xrbRvNeU00LlZuXhKUWZ2QMT60=; b=dKHeDLb+bJpDJaNza4nPdGePRCTLaiz3SGRcbygTeHUQbj6L7/J+XUMZVDOfJJ0bVSobJg BhOW4iPHreqFHUKL0AsZIlqcImIlLV6ycZKTQZiSBkwtLiIiTx9JWcPajzZk9MBCgUX8qP KNABLci16dqwQGZ1QDFz42INfIMVGoo= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-508-TSpCiGPCNIy3dGXn8PeGzg-1; Mon, 02 Nov 2020 21:34:04 -0500 X-MC-Unique: TSpCiGPCNIy3dGXn8PeGzg-1 Received: by mail-pg1-f199.google.com with SMTP id f2so10548094pgf.5 for ; Mon, 02 Nov 2020 18:34:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VR9Xpzs08VUXpHhn7xrbRvNeU00LlZuXhKUWZ2QMT60=; b=lmWnT3Ih4dQkDX74KwdI5cpQC7lkTHrLADtjRvwvbHH9nmkPIzN1TlxF/ABWUtH7wA 6hQdAg0vuSMYz+vK7ATwXMHN0I+o/oWcJrUE5YNjJoWYmb7Bre7lqkoCxgI7LbaiIU9x ouxIT++/yayJioy5SVxp+PH06BYYXqhE7cwedaW6m/QnnvtXo/k5hqZfpblQp4pBmiQB p3fysS0nUnSGQ6qJmWXhYcLPYaoZOc/f9MJ+7mkbzYy/jUZz7HANlIdJE+yfN6ajSeTw RbKLVdwXAMVeDmeA/u+/Lfkj1b3hufOS4yRRtyDM/sPNDFVAZyp/fEpXyXsPC11u084I 2etQ== X-Gm-Message-State: AOAM531BliJGwBTSpCRgMl4U3QKWhn7egpc8xhjftiVRtStO4BIaxIv3 uw7mBdUMoVRcLQOQBIndjmO7mSDjNnOt0caHefP401xm3hrUdauekanSGEnG1MpmJzAVr9Et/bM OoRLi841Svdh28t3BgE0x X-Received: by 2002:aa7:96f9:0:b029:18a:aaea:20f6 with SMTP id i25-20020aa796f90000b029018aaaea20f6mr13951451pfq.41.1604370842955; Mon, 02 Nov 2020 18:34:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxOcOq1OzI08AuLce5e4toE7KaZcxTQHg3OJjQ/BMFiW7lG+fnVMShubfnRVeKEKHNqu+fwyQ== X-Received: by 2002:aa7:96f9:0:b029:18a:aaea:20f6 with SMTP id i25-20020aa796f90000b029018aaaea20f6mr13951432pfq.41.1604370842526; Mon, 02 Nov 2020 18:34:02 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id u11sm14251253pfk.164.2020.11.02.18.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 18:34:02 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Gao Xiang , Eric Sandeen Subject: [PATCH v2 1/2] xfsdump: Revert "xfsdump: handle bind mount targets" Date: Tue, 3 Nov 2020 10:33:14 +0800 Message-Id: <20201103023315.786103-1-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.1 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Bind mount mntpnts will be forbided in the next commits instead since it's not the real rootdir. This cannot be reverted cleanly due to several cleanup patches, but the logic is reverted equivalently. This reverts commit 25195ebf107dc81b1b7cea1476764950e1d6cc9d. Fixes: 25195ebf107d ("xfsdump: handle bind mount targets") Cc: Eric Sandeen Signed-off-by: Gao Xiang Reviewed-by: Eric Sandeen Reviewed-by: Bill O'Donnell --- dump/content.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/dump/content.c b/dump/content.c index 30232d4..c11d9b4 100644 --- a/dump/content.c +++ b/dump/content.c @@ -1382,17 +1382,10 @@ baseuuidbypass: } /* figure out the ino for the root directory of the fs - * and get its struct xfs_bstat for inomap_build(). This could - * be a bind mount; don't ask for the mount point inode, - * find the actual lowest inode number in the filesystem. + * and get its xfs_bstat_t for inomap_build() */ { stat64_t rootstat; - xfs_ino_t lastino = 0; - int ocount = 0; - struct xfs_fsop_bulkreq bulkreq; - - /* Get the inode of the mount point */ rval = fstat64(sc_fsfd, &rootstat); if (rval) { mlog(MLOG_NORMAL, _( @@ -1404,21 +1397,11 @@ baseuuidbypass: (struct xfs_bstat *)calloc(1, sizeof(struct xfs_bstat)); assert(sc_rootxfsstatp); - /* Get the first valid (i.e. root) inode in this fs */ - bulkreq.lastip = (__u64 *)&lastino; - bulkreq.icount = 1; - bulkreq.ubuffer = sc_rootxfsstatp; - bulkreq.ocount = &ocount; - if (ioctl(sc_fsfd, XFS_IOC_FSBULKSTAT, &bulkreq) < 0) { + if (bigstat_one(sc_fsfd, rootstat.st_ino, sc_rootxfsstatp) < 0) { mlog(MLOG_ERROR, _("failed to get bulkstat information for root inode\n")); return BOOL_FALSE; } - - if (sc_rootxfsstatp->bs_ino != rootstat.st_ino) - mlog (MLOG_NORMAL | MLOG_NOTE, - _("root ino %lld differs from mount dir ino %lld, bind mount?\n"), - sc_rootxfsstatp->bs_ino, rootstat.st_ino); } /* alloc a file system handle, to be used with the jdm_open() From patchwork Tue Nov 3 02:33:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 11875777 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 2A901697 for ; Tue, 3 Nov 2020 02:34:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DAAC22275 for ; Tue, 3 Nov 2020 02:34:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UXjnXnLw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726042AbgKCCeL (ORCPT ); Mon, 2 Nov 2020 21:34:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47090 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbgKCCeL (ORCPT ); Mon, 2 Nov 2020 21:34:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604370850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=uC2t3wztcLYU//GjBY6JydOXVvD7q4rUOIvlzDo0EZI=; b=UXjnXnLwUwqvA90/KWZQmn2r3m7T8FABcxm45xbDDX1y7YZ14fj3XHZbqbYGSitYb6tyyr Z2QrXA8s6/B2eoVrvUw4pQypVdy9U+p0GiI7GYtznFs2MjWd/NAWtfAlWfmvLWtujQkFyz OpPBeSAOVzAiDR7QagLtzcLqsvjjiq8= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-ktZgKHJQPUKBQv9SAnzXcg-1; Mon, 02 Nov 2020 21:34:08 -0500 X-MC-Unique: ktZgKHJQPUKBQv9SAnzXcg-1 Received: by mail-pf1-f198.google.com with SMTP id 64so11350020pfg.9 for ; Mon, 02 Nov 2020 18:34:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uC2t3wztcLYU//GjBY6JydOXVvD7q4rUOIvlzDo0EZI=; b=Pm/7db0eg0X5rRL/OYQfto5AEGC5GNa6kO4FIc8emu+GqqJe7qLk1tQRb8RO3J0pdC tNZkgStlZIexWM5C6MAH7+AxykZdHZTOBk3j2xmxm+LCuJw4qhi9ECbxaD4xJKDobpXW 7s5nWrNrnTO1uP6KuiK0zn2GXVRof7z1ELcimuXrIAu03xtmlbKk0URvJVfrKFZaFCdh /oKECNbatu4Y8k7wA/bHi2i39kHUIyFnvr1KdUH0t18tM0m6rtUFqBCZFdIYaDnDQBgR 9kxOtOYVOv4OFyH3WgRGewocL+G0tAnhVhoMpd8pyxIzG1s1xzzd7SZms1bNUPn4G40b zRAg== X-Gm-Message-State: AOAM533XTsO7E6xlOvwKCJ1SX5GU+XkKIoygaZkock/y/I5y3HSIUcEk CCL1eMcjw94z35IA57000VwEtk0QAJibl81Np2gvsyRXn/GL/Z+DS9DSOF1JLph1B01lRCT3jNC WtkRKD3U/vTax6bWzsZBr X-Received: by 2002:a63:b245:: with SMTP id t5mr15290729pgo.328.1604370847291; Mon, 02 Nov 2020 18:34:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJyIWK+/fM8DXxDXvFoxhZ6MH0Jbjt4dCLtBTK4yhn1V5kDxoo4RjZsyla2FpV2PmqVMANwDog== X-Received: by 2002:a63:b245:: with SMTP id t5mr15290718pgo.328.1604370847092; Mon, 02 Nov 2020 18:34:07 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id u11sm14251253pfk.164.2020.11.02.18.34.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 18:34:06 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Gao Xiang , Eric Sandeen Subject: [PATCH v2 2/2] xfsdump: intercept bind mount targets Date: Tue, 3 Nov 2020 10:33:15 +0800 Message-Id: <20201103023315.786103-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20201103023315.786103-1-hsiangkao@redhat.com> References: <20201103023315.786103-1-hsiangkao@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org It's a bit strange pointing at some non-root bind mount target and then actually dumping from the actual root dir instead. Therefore, instead of searching for the root dir of the filesystem, just intercept all bind mount targets by checking whose ino # of ".." is itself with getdents. Fixes: 25195ebf107d ("xfsdump: handle bind mount targets") Cc: Eric Sandeen Signed-off-by: Gao Xiang --- changes since v1: just intercept bind mount targets suggested by Eric on IRC instead, and no need to use XFS_BULK_IREQ_SPECIAL_ROOT since the xfs header files and the kernel on my laptop don't support it, plus xfsdump/xfsrestore are not part of xfsprogs, so a bit hard to sync and make full use of that elegantly. dump/content.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/dump/content.c b/dump/content.c index c11d9b4..7a55b92 100644 --- a/dump/content.c +++ b/dump/content.c @@ -511,6 +511,61 @@ static bool_t create_inv_session( ix_t subtreecnt, size_t strmix); +static bool_t +check_rootdir(int fd, + xfs_ino_t ino) +{ + struct dirent *gdp; + size_t gdsz; + + gdsz = sizeof(struct dirent) + NAME_MAX + 1; + if (gdsz < GETDENTSBUF_SZ_MIN) + gdsz = GETDENTSBUF_SZ_MIN; + gdp = (struct dirent *)calloc(1, gdsz); + assert(gdp); + + while (1) { + struct dirent *p; + int nread; + + nread = getdents_wrap(fd, (char *)gdp, gdsz); + /* + * negative count indicates something very bad happened; + * try to gracefully end this dir. + */ + if (nread < 0) { + mlog(MLOG_NORMAL | MLOG_WARNING, +_("unable to read dirents for directory ino %llu: %s\n"), + ino, strerror(errno)); + /* !!! curtis looked at this, and pointed out that + * we could take some recovery action here. if the + * errno is appropriate, lseek64 to the value of + * doff field of the last dirent successfully + * obtained, and contiue the loop. + */ + nread = 0; /* pretend we are done */ + } + + /* no more directory entries: break; */ + if (!nread) + break; + + for (p = gdp; nread > 0; + nread -= (int)p->d_reclen, + assert(nread >= 0), + p = (struct dirent *)((char *)p + p->d_reclen)) { + if (!strcmp(p->d_name, "..") && p->d_ino == ino) { + mlog(MLOG_DEBUG, "FOUND: name %s d_ino %llu\n", + p->d_name, ino); + free(gdp); + return BOOL_TRUE; + } + } + } + free(gdp); + return BOOL_FALSE; +} + bool_t content_init(int argc, char *argv[], @@ -1393,6 +1448,13 @@ baseuuidbypass: mntpnt); return BOOL_FALSE; } + + if (!check_rootdir(sc_fsfd, rootstat.st_ino)) { + mlog(MLOG_ERROR, +"oops, seems to be a bind mount, please use the actual mountpoint instead\n"); + return BOOL_FALSE; + } + sc_rootxfsstatp = (struct xfs_bstat *)calloc(1, sizeof(struct xfs_bstat)); assert(sc_rootxfsstatp);