cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 1/2] gfs2_edit savemeta: Fix up saving of dinodes/symlinks
Date: Thu, 17 Aug 2017 18:10:26 +0100	[thread overview]
Message-ID: <20170817171027.8449-1-anprice@redhat.com> (raw)

Factor out the code that decides whether to save the dinode contents,
improve its error reporting (and don't exit) and make sure contents of
symlink dinodes are saved.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/edit/savemeta.c | 52 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 19 deletions(-)

diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index dee405bc..6ae38274 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -190,6 +190,38 @@ static const char *anthropomorphize(unsigned long long inhuman_value)
 	return out_val;
 }
 
+static int di_save_len(struct gfs2_buffer_head *bh, uint64_t owner)
+{
+	struct gfs2_inode *inode;
+	struct gfs2_dinode *dn;
+	int len;
+
+	if (sbd.gfs1)
+		inode = lgfs2_gfs_inode_get(&sbd, bh);
+	else
+		inode = lgfs2_inode_get(&sbd, bh);
+
+	if (inode == NULL) {
+		fprintf(stderr, "Error reading inode at %"PRIu64": %s\n",
+		        bh->b_blocknr, strerror(errno));
+		return 0; /* Skip the block */
+	}
+	dn = &inode->i_di;
+	len = sbd.bsize;
+
+	/* Do not save (user) data from stuffed inodes unless they are
+	   indirect pointers, dirents, symlinks or fs internal data */
+	if (dn->di_height == 0 &&
+	    !S_ISDIR(dn->di_mode) &&
+	    !S_ISLNK(dn->di_mode) &&
+	    (sbd.gfs1 && dn->__pad1 != GFS_FILE_DIR) &&
+	    !block_is_systemfile(owner))
+		len = sizeof(struct gfs2_dinode);
+
+	inode_put(&inode);
+	return len;
+}
+
 /*
  * get_gfs_struct_info - get block type and structure length
  *
@@ -205,7 +237,6 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, uint64_t owner,
                                int *block_type, int *gstruct_len)
 {
 	struct gfs2_meta_header mh;
-	struct gfs2_inode *inode;
 
 	if (block_type != NULL)
 		*block_type = 0;
@@ -229,24 +260,7 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, uint64_t owner,
 		*gstruct_len = sbd.bsize;
 		break;
 	case GFS2_METATYPE_DI:   /* 4 (disk inode) */
-		if (sbd.gfs1) {
-			inode = lgfs2_gfs_inode_get(&sbd, lbh);
-		} else {
-			inode = lgfs2_inode_get(&sbd, lbh);
-		}
-		if (inode == NULL) {
-			perror("Error reading inode");
-			exit(-1);
-		}
-		if (S_ISDIR(inode->i_di.di_mode) ||
-		     (sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
-			*gstruct_len = sbd.bsize;
-		else if (!inode->i_di.di_height && !block_is_systemfile(owner) &&
-			 !S_ISDIR(inode->i_di.di_mode))
-			*gstruct_len = sizeof(struct gfs2_dinode);
-		else
-			*gstruct_len = sbd.bsize;
-		inode_put(&inode);
+		*gstruct_len = di_save_len(lbh, owner);
 		break;
 	case GFS2_METATYPE_IN:   /* 5 (indir inode blklst) */
 		*gstruct_len = sbd.bsize; /*sizeof(struct gfs_indirect);*/
-- 
2.13.5



             reply	other threads:[~2017-08-17 17:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-17 17:10 Andrew Price [this message]
2017-08-17 17:10 ` [Cluster-devel] [PATCH 2/2] gfs2_edit savemeta: Use size_t for saved structure lengths Andrew Price
2017-08-17 18:09 ` [Cluster-devel] [PATCH 1/2] gfs2_edit savemeta: Fix up saving of dinodes/symlinks Bob Peterson
2017-08-17 19:35 ` Andrew Price

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=20170817171027.8449-1-anprice@redhat.com \
    --to=anprice@redhat.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).