From 587c6c14de739603ac99a467c8087793c5b1591d Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Thu, 10 Dec 2015 19:51:12 +0900 Subject: [PATCH] sys/vfs/hammer: Use hammer_find_inode() Add __hammer_find_inode() and make hammer_get_*inode() use this. __hammer_find_inode() is no-ref version of hammer_find_inode() directly called by hammer_find_inode(). Neither three function arguments obj_id, asof, localization nor three fields of struct hammer_inode_info are modified in hammer_get_inode() and hammer_get_dummy_inode(), so getting rid of hammer_inode_info initialization placed before loop: is ok. --- sys/vfs/hammer/hammer_inode.c | 51 ++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/sys/vfs/hammer/hammer_inode.c b/sys/vfs/hammer/hammer_inode.c index 55f398e8a3..bfeeb94101 100644 --- a/sys/vfs/hammer/hammer_inode.c +++ b/sys/vfs/hammer/hammer_inode.c @@ -51,6 +51,9 @@ static int hammer_setup_parent_inodes_helper(hammer_record_t record, static void hammer_inode_wakereclaims(hammer_inode_t ip); static struct hammer_inostats *hammer_inode_inostats(hammer_mount_t hmp, pid_t pid); +static struct hammer_inode *__hammer_find_inode(hammer_transaction_t trans, + int64_t obj_id, hammer_tid_t asof, + uint32_t localization); struct krate hammer_gen_krate = { 1 }; @@ -418,7 +421,6 @@ hammer_get_inode(hammer_transaction_t trans, hammer_inode_t dip, { hammer_mount_t hmp = trans->hmp; struct hammer_node_cache *cachep; - struct hammer_inode_info iinfo; struct hammer_cursor cursor; struct hammer_inode *ip; @@ -439,18 +441,15 @@ hammer_get_inode(hammer_transaction_t trans, hammer_inode_t dip, * link count. hammer_vop_nresolve() uses hammer_get_dummy_inode() * to ref dummy inodes. */ - iinfo.obj_id = obj_id; - iinfo.obj_asof = asof; - iinfo.obj_localization = localization; loop: - ip = hammer_ino_rb_tree_RB_LOOKUP_INFO(&hmp->rb_inos_root, &iinfo); + *errorp = 0; + ip = __hammer_find_inode(trans, obj_id, asof, localization); if (ip) { if (ip->flags & HAMMER_INODE_DUMMY) { *errorp = ENOENT; return(NULL); } hammer_ref(&ip->lock); - *errorp = 0; return(ip); } @@ -461,7 +460,7 @@ loop: ++hammer_count_inodes; ++hmp->count_inodes; ip->obj_id = obj_id; - ip->obj_asof = iinfo.obj_asof; + ip->obj_asof = asof; ip->obj_localization = localization; ip->hmp = hmp; ip->flags = flags & HAMMER_INODE_RO; @@ -504,7 +503,7 @@ retry: cursor.key_beg.rec_type = HAMMER_RECTYPE_INODE; cursor.key_beg.obj_type = 0; - cursor.asof = iinfo.obj_asof; + cursor.asof = asof; cursor.flags = HAMMER_CURSOR_GET_LEAF | HAMMER_CURSOR_GET_DATA | HAMMER_CURSOR_ASOF; @@ -610,7 +609,6 @@ hammer_get_dummy_inode(hammer_transaction_t trans, hammer_inode_t dip, int flags, int *errorp) { hammer_mount_t hmp = trans->hmp; - struct hammer_inode_info iinfo; struct hammer_inode *ip; /* @@ -627,12 +625,9 @@ hammer_get_dummy_inode(hammer_transaction_t trans, hammer_inode_t dip, * If we find a non-fake inode we return an error. Only fake * inodes can be returned by this routine. */ - iinfo.obj_id = obj_id; - iinfo.obj_asof = asof; - iinfo.obj_localization = localization; loop: *errorp = 0; - ip = hammer_ino_rb_tree_RB_LOOKUP_INFO(&hmp->rb_inos_root, &iinfo); + ip = __hammer_find_inode(trans, obj_id, asof, localization); if (ip) { if ((ip->flags & HAMMER_INODE_DUMMY) == 0) { *errorp = ENOENT; @@ -649,7 +644,7 @@ loop: ++hammer_count_inodes; ++hmp->count_inodes; ip->obj_id = obj_id; - ip->obj_asof = iinfo.obj_asof; + ip->obj_asof = asof; ip->obj_localization = localization; ip->hmp = hmp; ip->flags = flags | HAMMER_INODE_RO | HAMMER_INODE_DUMMY; @@ -713,12 +708,31 @@ loop: /* * Return a referenced inode only if it is in our inode cache. - * * Dummy inodes do not count. */ struct hammer_inode * hammer_find_inode(hammer_transaction_t trans, int64_t obj_id, hammer_tid_t asof, uint32_t localization) +{ + struct hammer_inode *ip; + + ip = __hammer_find_inode(trans, obj_id, asof, localization); + if (ip) { + if (ip->flags & HAMMER_INODE_DUMMY) + ip = NULL; + else + hammer_ref(&ip->lock); + } + return(ip); +} + +/* + * Return a referenced inode only if it is in our inode cache. + * This function does not reference inode. + */ +static struct hammer_inode * +__hammer_find_inode(hammer_transaction_t trans, int64_t obj_id, + hammer_tid_t asof, uint32_t localization) { hammer_mount_t hmp = trans->hmp; struct hammer_inode_info iinfo; @@ -729,12 +743,7 @@ hammer_find_inode(hammer_transaction_t trans, int64_t obj_id, iinfo.obj_localization = localization; ip = hammer_ino_rb_tree_RB_LOOKUP_INFO(&hmp->rb_inos_root, &iinfo); - if (ip) { - if (ip->flags & HAMMER_INODE_DUMMY) - ip = NULL; - else - hammer_ref(&ip->lock); - } + return(ip); } -- 2.41.0