From: Bob Peterson <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [Patch 15/44] fsck.gfs2: Factor out function to add ".." entry when linking to lost+found
Date: Thu, 11 Aug 2011 17:04:50 -0400 (EDT) [thread overview]
Message-ID: <456780365.544721.1313096690447.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com> (raw)
From 37b96d287c82e81b5626948a80b52d62bb2b8612 Mon Sep 17 00:00:00 2001
From: Bob Peterson <rpeterso@redhat.com>
Date: Mon, 8 Aug 2011 15:44:19 -0500
Subject: [PATCH 15/44] fsck.gfs2: Factor out function to add ".." entry when
linking to lost+found
This function factors out a section of code from function add_inode_to_lf.
This makes it easier to read and gives it the ability to print better
messages regarding where the block was previously linked.
rhbz#675723
---
gfs2/fsck/lost_n_found.c | 125 ++++++++++++++++++++++++++--------------------
1 files changed, 70 insertions(+), 55 deletions(-)
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index b6f02b9..7ce5db5 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -17,6 +17,75 @@
#include "metawalk.h"
#include "util.h"
+static void add_dotdot(struct gfs2_inode *ip)
+{
+ struct dir_info *di;
+ struct gfs2_sbd *sdp = ip->i_sbd;
+ int err;
+
+ log_info( _("Adding .. entry to directory %llu (0x%llx) pointing back "
+ "to lost+found\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr);
+
+ /* If there's a pre-existing .. directory entry, we have to
+ back out the links. */
+ di = dirtree_find(ip->i_di.di_num.no_addr);
+ if (di && !valid_block(sdp, di->dotdot_parent) == 0) {
+ struct gfs2_inode *dip;
+
+ log_debug(_("Directory %lld (0x%llx) already had a "
+ "\"..\" link to %lld (0x%llx).\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)di->dotdot_parent,
+ (unsigned long long)di->dotdot_parent);
+ decr_link_count(di->dotdot_parent, ip->i_di.di_num.no_addr,
+ _(".. unlinked, moving to lost+found"));
+ dip = fsck_load_inode(sdp, di->dotdot_parent);
+ if (dip->i_di.di_nlink > 0) {
+ dip->i_di.di_nlink--;
+ set_di_nlink(dip); /* keep inode tree in sync */
+ log_debug(_("Decrementing its links to %d\n"),
+ dip->i_di.di_nlink);
+ bmodified(dip->i_bh);
+ } else if (!dip->i_di.di_nlink) {
+ log_debug(_("Its link count is zero.\n"));
+ } else {
+ log_debug(_("Its link count is %d! Changing "
+ "it to 0.\n"), dip->i_di.di_nlink);
+ dip->i_di.di_nlink = 0;
+ set_di_nlink(dip); /* keep inode tree in sync */
+ bmodified(dip->i_bh);
+ }
+ fsck_inode_put(&dip);
+ di = NULL;
+ } else {
+ if (di)
+ log_debug(_("Couldn't find a valid \"..\" entry "
+ "for orphan directory %lld (0x%llx): "
+ "'..' = 0x%llx\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)di->dotdot_parent);
+ else
+ log_debug(_("Couldn't find a valid \"..\" entry "
+ "for orphan directory %lld (0x%llx)\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr);
+ }
+ if (gfs2_dirent_del(ip, "..", 2))
+ log_warn( _("add_inode_to_lf: Unable to remove "
+ "\"..\" directory entry.\n"));
+
+ err = dir_add(ip, "..", 2, &(lf_dip->i_di.di_num), DT_DIR);
+ if (err) {
+ log_crit(_("Error adding .. directory: %s\n"),
+ strerror(errno));
+ exit(-1);
+ }
+}
+
/* add_inode_to_lf - Add dir entry to lost+found for the inode
* @ip: inode to add to lost + found
*
@@ -95,61 +164,7 @@ int add_inode_to_lf(struct gfs2_inode *ip){
switch(ip->i_di.di_mode & S_IFMT){
case S_IFDIR:
- log_info( _("Adding .. entry pointing to lost+found for "
- "directory %llu (0x%llx)\n"),
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr);
-
- /* If there's a pre-existing .. directory entry, we have to
- back out the links. */
- di = dirtree_find(ip->i_di.di_num.no_addr);
- if (di && !valid_block(sdp, di->dotdot_parent) == 0) {
- struct gfs2_inode *dip;
-
- log_debug(_("Directory %lld (0x%llx) already had a "
- "\"..\" link to %lld (0x%llx).\n"),
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)di->dotdot_parent,
- (unsigned long long)di->dotdot_parent);
- decr_link_count(di->dotdot_parent,
- ip->i_di.di_num.no_addr,
- _(".. unlinked, moving to lost+found"));
- dip = fsck_load_inode(sdp, di->dotdot_parent);
- if (dip->i_di.di_nlink > 0) {
- dip->i_di.di_nlink--;
- set_di_nlink(dip); /* keep inode tree in sync */
- log_debug(_("Decrementing its links to %d\n"),
- dip->i_di.di_nlink);
- bmodified(dip->i_bh);
- } else if (!dip->i_di.di_nlink) {
- log_debug(_("Its link count is zero.\n"));
- } else {
- log_debug(_("Its link count is %d! "
- "Changing it to 0.\n"),
- dip->i_di.di_nlink);
- dip->i_di.di_nlink = 0;
- set_di_nlink(dip); /* keep inode tree in sync */
- bmodified(dip->i_bh);
- }
- fsck_inode_put(&dip);
- di = NULL;
- } else
- log_debug(_("Couldn't find a valid \"..\" entry "
- "for orphan directory %lld (0x%llx)\n"),
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr);
- if (gfs2_dirent_del(ip, "..", 2))
- log_warn( _("add_inode_to_lf: Unable to remove "
- "\"..\" directory entry.\n"));
-
- err = dir_add(ip, "..", 2, &(lf_dip->i_di.di_num), DT_DIR);
- if (err) {
- log_crit(_("Error adding .. directory: %s\n"),
- strerror(errno));
- exit(-1);
- }
-
+ add_dotdot(ip);
sprintf(tmp_name, "lost_dir_%llu",
(unsigned long long)ip->i_di.di_num.no_addr);
inode_type = DT_DIR;
--
1.7.4.4
next reply other threads:[~2011-08-11 21:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-11 21:04 Bob Peterson [this message]
2011-08-12 9:31 ` [Cluster-devel] [Patch 15/44] fsck.gfs2: Factor out function to add ".." entry when linking to lost+found Steven Whitehouse
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=456780365.544721.1313096690447.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com \
--to=rpeterso@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).