Skip to contentSkip to conversation

e2fsprogs: user selectable dup block handling in fsck (fwd)

PATCH In review Jim Garlick 2 participants 4 messages Feb 5, 2007 – Apr 11, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 e2fsprogs: user selectable dup block handling in fsck (fwd)

This is a refresh of the e2fsck patches I sent last week, reflecting comments received from the list and correcting one oversight.

The first patch (below), in addition to causing the config file to be parsed before command line args, now makes -E parsing cumulative.

The second patch has some cosmetic changes and a bug fix - now it gets the block bitmap and block alloc stats right after clone=zero processing.

Thanks,

Jim

---------- Forwarded message ----------
Date: Wed, 31 Jan 2007 08:22:20 -0800 (PST)
From: Jim Garlick <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [patch 1/2] e2fsprogs: user selectable dup block handling in fsck

Hello,

E2fsck fixes files that are found to be sharing blocks by cloning the shared blocks and giving each file a private copy in pass 1D.

Allowing all files claiming the shared blocks to have copies can
inadvertantly bypass access restrictions. Deleting all the files, zeroing the cloned blocks, or placing the files in the /lost+found directory after cloning may be preferable in some secure environments.

The following patches implement config file and command line options in e2fsck that allow pass 1D behavior to be tuned according to site policy.

The first patch changes the order that the config file and command line are parsed so that command line has precedence. It also adds a check to make sure only one -E option is passed on the command line as -E option parsing is not cumulative.

The second patch adds two extended options and config file counterparts. On the command line:

-E clone=dup|zero

Select the block cloning method. "dup" is old behavior which remains the default. "zero" is a new method that substitutes zero-filled blocks for the shared blocks in all the files that claim them.

-E shared=preserve|lost+found|delete

Select the disposition of files containing shared blocks. "preserve" is the old behavior which remains the default. "lost+found" causes files to be unlinked after cloning so they will be reconnected to
/lost+found in pass 3. "delete" skips cloning entirely and simply
deletes the files.

In the config file:
[options]
clone=dup|zero
shared=preserve|lost+found|delete

Regards,

Jim Garlick
Lawrence Livermore National Laboratory

e2fsck/unix.c +7 -9
Index: e2fsprogs+chaos/e2fsck/unix.c
===================================================================
@@ -583,7 +583,6 @@ static errcode_t PRS(int argc, char *arg
 #ifdef HAVE_SIGNAL_H
 	struct sigaction	sa;
 #endif
-	char		*extended_opts = 0;
 	char		*cp;
 
 	retval = e2fsck_allocate_context(&ctx);
@@ -610,6 +609,12 @@ static errcode_t PRS(int argc, char *arg
 		ctx->program_name = *argv;
 	else
 		ctx->program_name = "e2fsck";
+
+	if ((cp = getenv("E2FSCK_CONFIG")) != NULL)
+		config_fn[0] = cp;
+	profile_set_syntax_err_cb(syntax_err_report);
+	profile_init(config_fn, &ctx->profile);
+
 	while ((c = getopt (argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDk")) != EOF)
 		switch (c) {
 		case 'C':
@@ -633,7 +638,7 @@ static errcode_t PRS(int argc, char *arg
 			ctx->options |= E2F_OPT_COMPRESS_DIRS;
 			break;
 		case 'E':
-			extended_opts = optarg;
+			parse_extended_opts(ctx, optarg);
 			break;
 		case 'p':
 		case 'a':
@@ -753,13 +758,6 @@ static errcode_t PRS(int argc, char *arg
 			argv[optind]);
 		fatal_error(ctx, 0);
 	}
-	if (extended_opts)
-		parse_extended_opts(ctx, extended_opts);
-
-	if ((cp = getenv("E2FSCK_CONFIG")) != NULL)
-		config_fn[0] = cp;
-	profile_set_syntax_err_cb(syntax_err_report);
-	profile_init(config_fn, &ctx->profile);
 
 	if (flush) {
 		fd = open(ctx->filesystem_name, O_RDONLY, 0);
e2fsck/ChangeLog +5 -0
Index: e2fsprogs+chaos/e2fsck/ChangeLog
===================================================================
@@ -1,3 +1,8 @@
+2007-01-30  Jim Garlick  <[email protected]>
+
+	* unix.c: Parse config file before command line so command line
+		has precedence.  Make -E option parsing cumulative.
+
 2006-11-14  Theodore Tso  <[email protected]>
 
 	* unix.c (PRS): Always allocate the replacement PATH environment
#1 lore raw

PATCH 2/2 e2fsprogs: user selectable dup block handling in fsck (fwd)

Second patch that implements new options for shared block handling in e2fsck pass 1D.

e2fsck/e2fsck.h +11 -0
Index: e2fsprogs+chaos/e2fsck/e2fsck.h
===================================================================
@@ -181,6 +181,17 @@ struct resource_track {
 #define E2F_PASS_5	5
 #define E2F_PASS_1B	6
 
+typedef	enum { +	E2F_SHARED_PRESERVE = 0, +	E2F_SHARED_DELETE,
+	E2F_SHARED_LPF
+} shared_opt_t;
+
+typedef enum {
+	E2F_CLONE_DUP = 0,
+	E2F_CLONE_ZERO
+} clone_opt_t;
+
 /*
  * Define the extended attribute refcount structure
  */
@@ -332,6 +343,8 @@ struct e2fsck_struct {
 	time_t now;
 
 	int ext_attr_ver;
+	shared_opt_t shared;
+	clone_opt_t clone;
 
 	profile_t	profile;
 
e2fsck/unix.c +70 -0

94 lines not on this page · raw message

e2fsck/pass1b.c +34 -11

84 lines not on this page · raw message

e2fsck/problem.h +6 -1
Index: e2fsprogs+chaos/e2fsck/problem.h
===================================================================
@@ -536,7 +536,13 @@ struct problem_context {
 
 /* Couldn't clone file (error) */
 #define PR_1D_CLONE_ERROR	0x013008
- +
+/* File with shared blocks found */
+#define PR_1D_DISCONNECT_QUESTION 0x013009
+
+/* Couldn't unlink file (error) */
+#define PR_1D_DISCONNECT_ERROR	0x01300A
+
 /*
  * Pass 2 errors
  */
e2fsck/problem.c +8 -0
Index: e2fsprogs+chaos/e2fsck/problem.c
===================================================================
@@ -912,6 +912,14 @@ static struct e2fsck_problem problem_tab
 	{ PR_1D_CLONE_ERROR,
 	  N_("Couldn't clone file: %m\n"), PROMPT_NONE, 0 },
 
+	/* File with shared blocks found */
+	{ PR_1D_DISCONNECT_QUESTION,
+	  N_("File with shared blocks found\n"), PROMPT_CONNECT, 0 },
+
+	/* Couldn't unlink file (error) */
+	{ PR_1D_DISCONNECT_ERROR,
+	  N_("Couldn't unlink file: %m\n"), PROMPT_NONE, 0 },
+
 	/* Pass 2 errors */
 
 	/* Pass 2: Checking directory structure */
e2fsck/e2fsck.8.in +9 -0
Index: e2fsprogs+chaos/e2fsck/e2fsck.8.in
===================================================================
@@ -165,6 +165,19 @@ following options are supported:
 Assume the format of the extended attribute blocks in the filesystem is
 the specified version number.  The version number may be 1 or 2.  The
 default extended attribute version format is 2.
+.TP
+.BI clone= dup|zero
+Resolve files with shared blocks in pass 1D by giving each file a private
+copy of the blocks (dup);
+or replacing the shared blocks with private, zero-filled blocks (zero). +The default is dup.
+.TP
+.BI shared= preserve|lost+found|delete
+Files with shared blocks discovered in pass 1D are cloned and then left +in place (preserve); +cloned and then disconnected from their parent directory,
+then reconnected to /lost+found in pass 3 (lost+found); +or simply deleted (delete).  The default is preserve.
 .RE
 .TP
 .B \-f
e2fsck/e2fsck.conf.5.in +11 -0
Index: e2fsprogs+chaos/e2fsck/e2fsck.conf.5.in
===================================================================
@@ -68,6 +68,7 @@ document.
 This stanza contains general configuration parameters for
 .BR e2fsck 's
 behavior.
+.TP
 .I [problems]
 This stanza allows the administrator to reconfigure how e2fsck handles
 various filesystem inconsistencies.
@@ -87,6 +88,20 @@ This boolean relation controls whether o
 filesystem checks (either based on time or number of mounts) should
 be doubled if the system is running on battery.  It defaults to
 true.
+.TP
+.I clone
+This string relation controls the default handling of shared blocks in pass 1D.
+It can be set to dup or zero.  See the
+.I "-E clone" +option description in e2fsck(8).
+.TP
+.I shared
+This string relation controls the default disposition of files discovered to +have shared blocks in pass 1D.  It can be set to preserve, lost+found, +or delete.  See the
+.I "-E shared" +option description in e2fsck(8).
+
 .SH THE [problems] STANZA
 Each tag in the
 .I [problems] 
e2fsck/ChangeLog +7 -0
Index: e2fsprogs+chaos/e2fsck/ChangeLog
===================================================================
@@ -1,5 +1,12 @@
 2007-01-30  Jim Garlick  <[email protected]>
 
+	* unix.c, pass1b.c, e2fsck.h : Add command line and config file
+		options to alter shared block handling method in pass 1D.
+
+	* problem.c, problem.h (PR_1D_DISCONNECT_*): Add new problem code.
+
+2007-01-30  Jim Garlick  <[email protected]>
+
 	* unix.c: Parse config file before command line so command line
 		has precedence.  Make -E option parsing cumulative.
#2 lore raw
Quoted 4 lines · Jim Garlick

Allowing all files claiming the shared blocks to have copies can inadvertantly bypass access restrictions. Deleting all the files, zeroing the cloned blocks, or placing the files in the /lost+found directory after cloning may be preferable in some secure environments.

My apologies for not having time to review your patches sooner. I've been insanely busy as of late.

The assumption was that the administrator would always review a list of files for correctness after running e2fsck, but this isn't necessarily easy because e2fsprogs doesn't create a log for such information in an easily accessible place. That may end up being the correct solution as opposed to trying to force that policy into e2fsck.

One of my long-term plans was to extend the fix_problem() function to log a detailed set of problems fixed into a file (either binary or XML) that could parsed by other programs as part of some kind of recovery process. What would get written out is the problem ID plus the entire problem_context structure, which has actually quite a lot of information. This would be enough for a lot of post-processing, including making it easier for people to implement policies such as deleted or archiving for review by the Site Security Officer any files which had some of their blocks cloned.

Quoted 7 lines

-E shared=preserve|lost+found|delete

Select the disposition of files containing shared blocks. "preserve" is the old behavior which remains the default. "lost+found" causes files to be unlinked after cloning so they will be reconnected to
/lost+found in pass 3. "delete" skips cloning entirely and simply
deletes the files.

lost+found does not work as you have implemented them in your patches in the case of a file which is hard linked. That's because in pass1c we only find the first directory where which contains a hard link to the file name, for the purpose of displaying a pathname that will hopefully have meaning to the system administrator. Currently, as implemented, if you specify a disposition of "lost+found", an inode which has multiple hard links will have one of its hard links removed, and since the rest of the links to the file are presend, it will not be moved into the lost+found directory.

So if you are using shared=lost+found at your site, you may want to use some other strategy until the patch is fixed to find and remove all links to that particular inode.

Regards,

- Ted

#3 lore raw

Re: [repost][patch 1/2] e2fsprogs: user selectable dup block handling in fsck

Quoted 9 lines · Theodore Tso

lost+found does not work as you have implemented them in your patches in the case of a file which is hard linked. That's because in pass1c we only find the first directory where which contains a hard link to the file name, for the purpose of displaying a pathname that will hopefully have meaning to the system administrator. Currently, as implemented, if you specify a disposition of "lost+found", an inode which has multiple hard links will have one of its hard links removed, and since the rest of the links to the file are presend, it will not be moved into the lost+found directory.

Thanks for catching this!

I like your idea of an xml log from e2fsck - meanwhile here's a reworked patch that deals with hard links in lost+found mode, in case its of use to anyone. Context assumes the following patches are
pre-applied:

[PATCH] e2fsprogs - pass1c terminates early if hard links
http://marc.info/?l=linux-ext4&m=117623796726589&w=2

[PATCH] e2fsprogs - e2fsck pass1c does extra work if root dir has
http://marc.info/?l=linux-ext4&m=117624460101811&w=2

[repost][patch 1/2] e2fsprogs: user selectable dup block handling
http://marc.info/?l=linux-ext4&m=117063892623654&w=2

Regards,

Jim
____________________________

E2fsck fixes files that are found to be sharing blocks by cloning the shared blocks and giving each file a private copy in pass 1D.

Allowing all files claiming the shared blocks to have copies can
inadvertantly bypass access restrictions. Deleting all the files, zeroing the cloned blocks, or placing the files in the /lost+found directory after cloning may be preferable in some secure environments.

The following patches implement config file and command line options in e2fsck that allow pass 1D behavior to be tuned according to site policy. It adds two extended options and config file counterparts. On the command line:

-E clone=dup|zero

Select the block cloning method. "dup" is old behavior which remains the default. "zero" is a new method that substitutes zero-filled blocks for the shared blocks in all the files that claim them.

-E shared=preserve|lost+found|delete

Select the disposition of files containing shared blocks. "preserve" is the old behavior which remains the default. "lost+found" causes files to be unlinked after cloning so they will be reconnected to
/lost+found in pass 3. "delete" skips cloning entirely and simply
deletes the files.

In the config file:
[options]
clone=dup|zero
shared=preserve|lost+found|delete

e2fsck/e2fsck.h +11 -0
Index: e2fsprogs+chaos/e2fsck/e2fsck.h
===================================================================
@@ -181,6 +181,17 @@ struct resource_track {
 #define E2F_PASS_5	5
 #define E2F_PASS_1B	6
 
+typedef	enum { +	E2F_SHARED_PRESERVE = 0, +	E2F_SHARED_DELETE,
+	E2F_SHARED_LPF
+} shared_opt_t;
+
+typedef enum {
+	E2F_CLONE_DUP = 0,
+	E2F_CLONE_ZERO
+} clone_opt_t;
+
 /*
  * Define the extended attribute refcount structure
  */
@@ -332,6 +343,8 @@ struct e2fsck_struct {
 	time_t now;
 
 	int ext_attr_ver;
+	shared_opt_t shared;
+	clone_opt_t clone;
 
 	profile_t	profile;
 
e2fsck/unix.c +70 -0

94 lines not on this page · raw message

e2fsck/pass1b.c +79 -20

227 lines not on this page · raw message

e2fsck/problem.h +6 -1
Index: e2fsprogs+chaos/e2fsck/problem.h
===================================================================
@@ -539,7 +539,13 @@ struct problem_context {
 
 /* Couldn't clone file (error) */
 #define PR_1D_CLONE_ERROR	0x013008
- +
+/* File with shared blocks found */
+#define PR_1D_DISCONNECT_QUESTION 0x013009
+
+/* Couldn't unlink file (error) */
+#define PR_1D_DISCONNECT_ERROR	0x01300A
+
 /*
  * Pass 2 errors
  */
e2fsck/problem.c +8 -0
Index: e2fsprogs+chaos/e2fsck/problem.c
===================================================================
@@ -912,6 +912,14 @@ static struct e2fsck_problem problem_tab
 	{ PR_1D_CLONE_ERROR,
 	  N_("Couldn't clone file: %m\n"), PROMPT_NONE, 0 },
 
+	/* File with shared blocks found */
+	{ PR_1D_DISCONNECT_QUESTION,
+	  N_("File with shared blocks found\n"), PROMPT_CONNECT, 0 },
+
+	/* Couldn't unlink file (error) */
+	{ PR_1D_DISCONNECT_ERROR,
+	  N_("Couldn't unlink file: %m\n"), PROMPT_NONE, 0 },
+
 	/* Pass 2 errors */
 
 	/* Pass 2: Checking directory structure */
e2fsck/e2fsck.8.in +9 -0
Index: e2fsprogs+chaos/e2fsck/e2fsck.8.in
===================================================================
@@ -165,6 +165,19 @@ following options are supported:
 Assume the format of the extended attribute blocks in the filesystem is
 the specified version number.  The version number may be 1 or 2.  The
 default extended attribute version format is 2.
+.TP
+.BI clone= dup|zero
+Resolve files with shared blocks in pass 1D by giving each file a private
+copy of the blocks (dup);
+or replacing the shared blocks with private, zero-filled blocks (zero). +The default is dup.
+.TP
+.BI shared= preserve|lost+found|delete
+Files with shared blocks discovered in pass 1D are cloned and then left +in place (preserve); +cloned and then disconnected from their parent directory,
+then reconnected to /lost+found in pass 3 (lost+found); +or simply deleted (delete).  The default is preserve.
 .RE
 .TP
 .B \-f
e2fsck/e2fsck.conf.5.in +11 -0
Index: e2fsprogs+chaos/e2fsck/e2fsck.conf.5.in
===================================================================
@@ -68,6 +68,7 @@ document.
 This stanza contains general configuration parameters for
 .BR e2fsck 's
 behavior.
+.TP
 .I [problems]
 This stanza allows the administrator to reconfigure how e2fsck handles
 various filesystem inconsistencies.
@@ -87,6 +88,20 @@ This boolean relation controls whether o
 filesystem checks (either based on time or number of mounts) should
 be doubled if the system is running on battery.  It defaults to
 true.
+.TP
+.I clone
+This string relation controls the default handling of shared blocks in pass 1D.
+It can be set to dup or zero.  See the
+.I "-E clone" +option description in e2fsck(8).
+.TP
+.I shared
+This string relation controls the default disposition of files discovered to +have shared blocks in pass 1D.  It can be set to preserve, lost+found, +or delete.  See the
+.I "-E shared" +option description in e2fsck(8).
+
 .SH THE [problems] STANZA
 Each tag in the
 .I [problems] 
e2fsck/ChangeLog +7 -0
Index: e2fsprogs+chaos/e2fsck/ChangeLog
===================================================================
@@ -1,5 +1,12 @@
 2007-01-30  Jim Garlick  <[email protected]>
 
+	* unix.c, pass1b.c, e2fsck.h : Add command line and config file
+		options to alter shared block handling method in pass 1D.
+
+	* problem.c, problem.h (PR_1D_DISCONNECT_*): Add new problem code.
+
+2007-01-30  Jim Garlick  <[email protected]>
+
 	* unix.c: Parse config file before command line so command line
 		has precedence.  Make -E option parsing cumulative.