From: Matthias Koenig <mkoenig@suse.de>
To: Theodore Ts'o <tytso@mit.edu>
Cc: ludwig.nussel@suse.de, linux-ext4@vger.kernel.org
Subject: [PATCH] [RFC] New fsck option to ignore device-mapper crypto devices
Date: Thu, 06 Mar 2008 14:41:22 +0100 [thread overview]
Message-ID: <n7xejaoynp9.fsf@sor.suse.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 1165 bytes --]
Hi,
Current practice in defining crypto devices in common distributions
has:
1. A definition of the device-mapper name with the corresponding device
in /etc/crypttab
2. A definition in /etc/fstab for the mountpoint of the dm device.
Steps involved into setting up the crypto devices are
a. fsck local filesystems
b. mount local filesystems
c. device-mapper set up of crypto devices
d. fsck crypto filesystems
e. mount crypto filesystems
Steps a.+b. have to be done before the crypto device setup, because
the crypto device could be in a file container on a local filesystem.
Now, the problem appears if /etc/fstab contains a mount point of a
crypto device which is supposed to be fsck'd in step d. fsck will
fail in step a., since this device does not exist at this point in
the boot process (it will be set up in step c.)
In order to address this, I propose a new option for fsck, lets say '-X'.
Enabling this will skip a device-mapper device which is currently
nonexistent, but is defined in /etc/crypttab.
In this way crypto devices could be skipped without fsck failure when
running fsck -A.
Proposed patch to implement this below.
Regards,
Matthias
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: e2fsprogs-1.40.7-ignore_crypto.patch --]
[-- Type: text/x-patch, Size: 3640 bytes --]
Index: e2fsprogs-1.40.7/misc/fsck.c
===================================================================
--- e2fsprogs-1.40.7.orig/misc/fsck.c
+++ e2fsprogs-1.40.7/misc/fsck.c
@@ -102,6 +102,7 @@ int noexecute = 0;
int serialize = 0;
int skip_root = 0;
int ignore_mounted = 0;
+int ignore_crypto = 0;
int notitle = 0;
int parallel_root = 0;
int progress = 0;
@@ -937,6 +938,67 @@ static int device_already_active(char *d
return 0;
}
+/*
+ * Check if a device exists
+ */
+static int device_exists(const char *device)
+{
+ struct stat st;
+
+ if (stat(device, &st) == -1)
+ return 0;
+
+ if (!S_ISBLK(st.st_mode))
+ return 0;
+
+ return 1;
+}
+
+static void skipline(FILE *file)
+{
+ int c;
+
+ do {
+ c = fgetc(file);
+ } while (c != '\n' && c != EOF);
+}
+
+/*
+ * Check if a device is defined in /etc/crypttab
+ */
+static int device_in_crypttab(const char *device)
+{
+ const char crypttab[]="/etc/crypttab";
+ const char dmpath[]="/dev/mapper/";
+ char name[1024];
+ FILE *file;
+
+ /* check if device is a dm device
+ * we can skip parsing if not
+ */
+ if (strncmp(dmpath, device, strlen(dmpath)) != 0)
+ return 0;
+
+ file = fopen(crypttab, "r");
+ if (!file)
+ return 0;
+
+ while (fscanf(file, "%1023s", name) == 1) {
+ if (name[0] == '#') {
+ skipline(file);
+ continue;
+ }
+
+ if (strcmp(device+strlen(dmpath), name) == 0) {
+ fclose(file);
+ return 1;
+ }
+ skipline(file);
+ }
+ fclose(file);
+ return 0;
+}
+
/* Check all file systems, using the /etc/fstab table. */
static int check_all(NOARGS)
{
@@ -1005,6 +1067,17 @@ static int check_all(NOARGS)
not_done_yet++;
continue;
}
+ /* ignore devices which do not exist yet, but are defined
+ * in /etc/crypttab
+ */
+ if (ignore_crypto && !device_exists(fs->device) &&
+ device_in_crypttab(fs->device)) {
+ if (verbose)
+ printf("Skipping nonexistent crypto device %s\n",
+ fs->device);
+ fs->flags |= FLAG_DONE;
+ continue;
+ }
if (ignore_mounted && is_mounted(fs->device)) {
fs->flags |= FLAG_DONE;
continue;
@@ -1058,7 +1131,7 @@ static int check_all(NOARGS)
static void usage(NOARGS)
{
- fputs(_("Usage: fsck [-AMNPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr);
+ fputs(_("Usage: fsck [-AMNPRTVX] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr);
exit(EXIT_USAGE);
}
@@ -1202,6 +1275,9 @@ static void PRS(int argc, char *argv[])
fstype = string_copy(tmp);
compile_fs_type(fstype, &fs_type_compiled);
goto next_arg;
+ case 'X':
+ ignore_crypto = 1;
+ break;
case '-':
opts_for_fsck++;
break;
@@ -1303,6 +1379,17 @@ int main(int argc, char *argv[])
if (!fs)
continue;
}
+ /*
+ * Ignore devices which do not exist,
+ * but are defined in /etc/crypttab
+ */
+ if (ignore_crypto && !device_exists(fs->device) &&
+ device_in_crypttab(fs->device)) {
+ if (verbose)
+ printf("Skipping nonexistent crypto device %s\n",
+ fs->device);
+ continue;
+ }
if (ignore_mounted && is_mounted(fs->device))
continue;
fsck_device(fs, interactive);
Index: e2fsprogs-1.40.7/misc/fsck.8.in
===================================================================
--- e2fsprogs-1.40.7.orig/misc/fsck.8.in
+++ e2fsprogs-1.40.7/misc/fsck.8.in
@@ -263,6 +263,10 @@ Don't show the title on startup.
Produce verbose output, including all file system-specific commands
that are executed.
.TP
+.B \-X
+Skip device-mapper devices which currently do not exist, but are defined in
+.BR crypttab (5).
+.TP
.B fs-specific-options
Options which are not understood by
.B fsck
next reply other threads:[~2008-03-06 13:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-06 13:41 Matthias Koenig [this message]
2008-03-06 14:32 ` [PATCH] [RFC] New fsck option to ignore device-mapper crypto devices Dave Kleikamp
2008-03-06 17:04 ` Matthias Koenig
2008-03-06 17:23 ` Dave Kleikamp
2008-03-06 17:42 ` Theodore Tso
2008-03-07 14:20 ` Matthias Koenig
2008-03-07 15:19 ` Dave Kleikamp
2008-03-12 15:59 ` Matthias Koenig
2008-03-12 20:02 ` Theodore Tso
2008-03-12 20:14 ` Theodore Tso
2008-03-13 5:37 ` Dave Kleikamp
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=n7xejaoynp9.fsf@sor.suse.de \
--to=mkoenig@suse.de \
--cc=linux-ext4@vger.kernel.org \
--cc=ludwig.nussel@suse.de \
--cc=tytso@mit.edu \
/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