[PATCH 03/19] e2fsck: use root dir for lost+found when really desperate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Darrick J. Wong <darrick.wong@xxxxxxxxxx>

If we're totally unable to allocate a lost+found directory, ask the
user if he would like to dump orphaned files in the root directory.
Hopefully this enables the user to delete enough files so that a
subsequent run of e2fsck will make more progress.  Better to cram lost
files in the rootdir than the current behavior, which is to fail at
linking them in, thereby leaving them as lost files.

Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
---
 e2fsck/pass3.c                    |   12 ++++++++++++
 e2fsck/problem.c                  |    5 +++++
 e2fsck/problem.h                  |    3 +++
 tests/f_nospc_create_lnf/expect.1 |   28 ++++++++++++++++++++++++++++
 tests/f_nospc_create_lnf/expect.2 |   25 +++++++++++++++++++++++++
 tests/f_nospc_create_lnf/image.gz |  Bin
 tests/f_nospc_create_lnf/name     |    1 +
 7 files changed, 74 insertions(+)
 create mode 100644 tests/f_nospc_create_lnf/expect.1
 create mode 100644 tests/f_nospc_create_lnf/expect.2
 create mode 100644 tests/f_nospc_create_lnf/image.gz
 create mode 100644 tests/f_nospc_create_lnf/name

diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c
index 31131ab..e6142ad 100644
--- a/e2fsck/pass3.c
+++ b/e2fsck/pass3.c
@@ -450,6 +450,12 @@ unlink:
 		goto skip_new_block;
 	}
 	retval = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
+	if (retval == EXT2_ET_BLOCK_ALLOC_FAIL &&
+	    fix_problem(ctx, PR_3_LPF_NO_SPACE, &pctx)) {
+		printf("Delete some files and re-run e2fsck.\n\n");
+		ctx->lost_and_found = EXT2_ROOT_INO;
+		return 0;
+	}
 	if (retval) {
 		pctx.errcode = retval;
 		fix_problem(ctx, PR_3_ERR_LPF_NEW_BLOCK, &pctx);
@@ -464,6 +470,12 @@ skip_new_block:
 	 */
 	retval = ext2fs_new_inode(fs, EXT2_ROOT_INO, 040700,
 				  ctx->inode_used_map, &ino);
+	if (retval == EXT2_ET_INODE_ALLOC_FAIL &&
+	    fix_problem(ctx, PR_3_LPF_NO_SPACE, &pctx)) {
+		printf("Delete some files and re-run e2fsck.\n\n");
+		ctx->lost_and_found = EXT2_ROOT_INO;
+		return 0;
+	}
 	if (retval) {
 		pctx.errcode = retval;
 		fix_problem(ctx, PR_3_ERR_LPF_NEW_INODE, &pctx);
diff --git a/e2fsck/problem.c b/e2fsck/problem.c
index 2c9386f..e68433b 100644
--- a/e2fsck/problem.c
+++ b/e2fsck/problem.c
@@ -1630,6 +1630,11 @@ static struct e2fsck_problem problem_table[] = {
 	  N_("/@l has inline data\n"),
 	  PROMPT_CLEAR, 0 },
 
+	/* Cannot allocate /lost+found. */
+	{ PR_3_LPF_NO_SPACE,
+	  N_("Cannot allocate space for /@l.\nPlace lost files in root directory instead"),
+	  PROMPT_NULL, 0 },
+
 	/* Pass 3A Directory Optimization	*/
 
 	/* Pass 3A: Optimizing directories */
diff --git a/e2fsck/problem.h b/e2fsck/problem.h
index 80ef4a2..496e873 100644
--- a/e2fsck/problem.h
+++ b/e2fsck/problem.h
@@ -973,6 +973,9 @@ struct problem_context {
 /* Lost+found has inline data */
 #define PR_3_LPF_INLINE_DATA		0x030018
 
+/* Cannot allocate lost+found */
+#define PR_3_LPF_NO_SPACE		0x030019
+
 /*
  * Pass 3a --- rehashing diretories
  */
diff --git a/tests/f_nospc_create_lnf/expect.1 b/tests/f_nospc_create_lnf/expect.1
new file mode 100644
index 0000000..fc20628
--- /dev/null
+++ b/tests/f_nospc_create_lnf/expect.1
@@ -0,0 +1,28 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+/lost+found not found.  Create? yes
+
+Cannot allocate space for /lost+found.
+Place lost files in root directory instead? yes
+
+Delete some files and re-run e2fsck.
+
+Pass 3A: Optimizing directories
+Pass 4: Checking reference counts
+Unattached inode 125
+Connect to /lost+found? yes
+
+Inode 125 ref count is 2, should be 1.  Fix? yes
+
+Pass 5: Checking group summary information
+Free blocks count wrong for group #0 (496, counted=495).
+Fix? yes
+
+Free blocks count wrong (496, counted=495).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 128/128 files (0.0% non-contiguous), 17/512 blocks
+Exit status is 1
diff --git a/tests/f_nospc_create_lnf/expect.2 b/tests/f_nospc_create_lnf/expect.2
new file mode 100644
index 0000000..5a44649
--- /dev/null
+++ b/tests/f_nospc_create_lnf/expect.2
@@ -0,0 +1,25 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+/lost+found not found.  Create? yes
+
+Cannot allocate space for /lost+found.
+Place lost files in root directory instead? yes
+
+Delete some files and re-run e2fsck.
+
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -9
+Fix? yes
+
+Free blocks count wrong for group #0 (494, counted=495).
+Fix? yes
+
+Free blocks count wrong (494, counted=495).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 128/128 files (0.0% non-contiguous), 17/512 blocks
+Exit status is 1
diff --git a/tests/f_nospc_create_lnf/image.gz b/tests/f_nospc_create_lnf/image.gz
new file mode 100644
index 0000000000000000000000000000000000000000..dc71b61a0028603aac348c61b015fd3c0b25273a
GIT binary patch
literal 4201
zcmeHH{Zms{8qRK~jkCIDtaWjUB+hmRwcAP&l#L18rEX>XB6YHbwR~hNB9l_cB9?dw
z<my^Wtz&|VihM|lSwTff`KY3S+}bE#0kSOGs3ZXek`PFugb?#_@7cp%e(Vqa0c7UQ
z%{lM$KIeI#^WLydEusCh<O%=RuQ^O;Tb*Y${kgT;B9FYkY}MY?fB0yVuHy6uJ#T&}
zjC^ZvZR`H#ukWPxyt(uI$2)h1?mYGFd7=EO@N(tO9ZN3%^+3fg=SaReaOG^mi5W?p
zqEX^>^|cR~yu0%Y^^+H~E8nm+r1geq_qbpF4G;Bq-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Q1>vB^q^>^6*8A&D5E6uY2(mPRsUTAE2YBbu~fjvQ9|
zyVNA%@D5Wreu1YgOtnyw13Qo;18a_Nh-wnlS_uFzr3E#NQ_jd_WV!UPDSKgx>q}5@
z(mRL+O@823V1$eGeUHI=?=~tX<_l)spd9v?oeWOAWBC8h1FT2ehWz5c<l^R{1B(tU
bI<V-#q63Q#yqW_*K`wuwV)xT%Yia)j*ECk;

literal 0
HcmV?d00001

diff --git a/tests/f_nospc_create_lnf/name b/tests/f_nospc_create_lnf/name
new file mode 100644
index 0000000..df6c932
--- /dev/null
+++ b/tests/f_nospc_create_lnf/name
@@ -0,0 +1 @@
+no space to create lost+found

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux