From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 3/6] libgfs2: Reorganise lgfs2_createi()
Date: Mon, 30 Jan 2023 15:21:43 +0000 [thread overview]
Message-ID: <20230130152146.633484-4-anprice@redhat.com> (raw)
In-Reply-To: <20230130152146.633484-1-anprice@redhat.com>
Move the lookup for an existing inode to lgfs2_createi itself and then
create the inode in __createi (renamed to do_createi) unconditionally.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/libgfs2/fs_ops.c | 80 ++++++++++++++++++++++++-------------------
1 file changed, 45 insertions(+), 35 deletions(-)
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 5003c1ae..0df78e5a 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1497,9 +1497,10 @@ int lgfs2_write_filemeta(struct lgfs2_inode *ip)
return 0;
}
-static struct lgfs2_inode *__createi(struct lgfs2_inode *dip, const char *filename,
- unsigned int mode, uint32_t flags)
+static struct lgfs2_inode *do_createi(struct lgfs2_inode *dip, const char *filename,
+ unsigned int mode, uint32_t flags)
{
+ struct lgfs2_inum parent = dip->i_num;
struct lgfs2_sbd *sdp = dip->i_sbd;
uint64_t bn;
struct lgfs2_inum inum;
@@ -1508,50 +1509,59 @@ static struct lgfs2_inode *__createi(struct lgfs2_inode *dip, const char *filena
int err = 0;
int is_dir;
- ip = lgfs2_lookupi(dip, filename, strlen(filename));
- if (!ip) {
- struct lgfs2_inum parent = dip->i_num;
-
- err = lgfs2_dinode_alloc(sdp, 1, &bn);
- if (err != 0)
- return NULL;
-
- if (sdp->gfs1)
- inum.in_formal_ino = bn;
- else
- inum.in_formal_ino = sdp->md.next_inum++;
- inum.in_addr = bn;
-
- err = lgfs2_dir_add(dip, filename, strlen(filename), &inum, IF2DT(mode));
- if (err)
- return NULL;
+ err = lgfs2_dinode_alloc(sdp, 1, &bn);
+ if (err != 0)
+ return NULL;
- if (sdp->gfs1)
- is_dir = (IF2DT(mode) == GFS_FILE_DIR);
- else
- is_dir = S_ISDIR(mode);
- if (is_dir) {
- lgfs2_bmodified(dip->i_bh);
- dip->i_nlink++;
- }
+ if (sdp->gfs1)
+ inum.in_formal_ino = bn;
+ else
+ inum.in_formal_ino = sdp->md.next_inum++;
+ inum.in_addr = bn;
- err = __init_dinode(sdp, &bh, &inum, mode, flags, &parent, sdp->gfs1);
- if (err != 0)
- return NULL;
+ err = lgfs2_dir_add(dip, filename, strlen(filename), &inum, IF2DT(mode));
+ if (err)
+ return NULL;
- ip = lgfs2_inode_get(sdp, bh);
- if (ip == NULL)
- return NULL;
- lgfs2_bmodified(bh);
+ if (sdp->gfs1)
+ is_dir = (IF2DT(mode) == GFS_FILE_DIR);
+ else
+ is_dir = S_ISDIR(mode);
+ if (is_dir) {
+ lgfs2_bmodified(dip->i_bh);
+ dip->i_nlink++;
}
+ err = __init_dinode(sdp, &bh, &inum, mode, flags, &parent, sdp->gfs1);
+ if (err != 0)
+ return NULL;
+
+ ip = lgfs2_inode_get(sdp, bh);
+ if (ip == NULL)
+ return NULL;
+ lgfs2_bmodified(bh);
ip->bh_owned = 1;
return ip;
}
+/**
+ * Create an inode and link it into a directory. If it already exists, return
+ * the existing inode. To create gfs1 inodes, dip->i_sbd->gfs1 must be set.
+ * @dip: The inode of the parent directory.
+ * @filename: The new inode's filename.
+ * @mode: The mode of the new inode.
+ * @flags: The flags of the new inode.
+ * Returns the new or existing inode on success or NULL on failure with errno set.
+ */
struct lgfs2_inode *lgfs2_createi(struct lgfs2_inode *dip, const char *filename,
unsigned int mode, uint32_t flags)
{
- return __createi(dip, filename, mode, flags);
+ struct lgfs2_inode *ip = lgfs2_lookupi(dip, filename, strlen(filename));
+
+ if (ip != NULL) {
+ ip->bh_owned = 1;
+ return ip;
+ }
+ return do_createi(dip, filename, mode, flags);
}
/**
--
2.39.0
next prev parent reply other threads:[~2023-01-30 15:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-30 15:21 [Cluster-devel] [PATCH 0/6] gfs2-utils: Cleanups and fsck.gfs2 fixes Andrew Price
2023-01-30 15:21 ` [Cluster-devel] [PATCH 1/6] libgfs2: Return the inode from lgfs2_lookupi() Andrew Price
2023-01-30 15:21 ` [Cluster-devel] [PATCH 2/6] libgfs2: Remove lgfs2_gfs_createi() Andrew Price
2023-01-30 15:21 ` Andrew Price [this message]
2023-01-30 15:21 ` [Cluster-devel] [PATCH 4/6] fsck.gfs2: Remove de variable from dirref_find() Andrew Price
2023-01-30 15:21 ` [Cluster-devel] [PATCH 5/6] fsck.gfs2: Fix wrong entry used in dentry comparison Andrew Price
2023-01-30 15:21 ` [Cluster-devel] [PATCH 6/6] fsck.gfs2: fix_hashtable: Decrement i_blocks when freeing leaf blocks 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=20230130152146.633484-4-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).