From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH v2] mkfs.gfs2: Check for symlinks before reporting device contents
Date: Thu, 21 Jun 2012 14:30:38 +0100 [thread overview]
Message-ID: <1340285438-12445-1-git-send-email-anprice@redhat.com> (raw)
(Patch updated to report symlinks similar to Fabio's suggestion)
When using symlinks with mkfs.gfs2 it reports what the symlink points
to instead of the contents of the device, like so:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
This will destroy any data on /dev/vg/test.
It appears to contain: symbolic link to `../dm-3'
This patch resolves symlinks before checking the device contents to make
the output more informative:
# ./mkfs.gfs2 -p lock_nolock /dev/vg/test
/dev/vg/test is a symlink to /dev/dm-3
This will destroy any data on /dev/dm-3.
It appears to contain: GFS2 Filesystem (blocksize 4096, lockproto lock_nolock)
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/mkfs/main_mkfs.c | 35 ++++++++++++++++++++++++++++++++---
1 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e6b00a0..957b144 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -518,19 +518,46 @@ print_results(struct gfs2_sbd *sdp, uint64_t real_device_size,
printf("\n");
}
+
+/**
+ * If path is a symlink, return 1 with *abspath pointing to the absolute path,
+ * otherwise return 0. Exit on errors. The caller must free the memory pointed
+ * to by *abspath.
+ */
+static int is_symlink(char *path, char **abspath)
+{
+ struct stat lnkstat;
+
+ if (lstat(path, &lnkstat) == -1) {
+ perror("Failed to lstat the device");
+ exit(EXIT_FAILURE);
+ }
+ if (!S_ISLNK(lnkstat.st_mode)) {
+ return 0;
+ }
+ *abspath = canonicalize_file_name(path);
+ if (*abspath == NULL) {
+ perror(_("Could not find the absolute path of the device"));
+ exit(EXIT_FAILURE);
+ }
+ printf( _("%s is a symlink to %s\n"), path, *abspath);
+ return 1;
+}
+
/**
* main_mkfs - do everything
* @argc:
* @argv:
*
*/
-
void main_mkfs(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
int error;
int rgsize_specified = 0;
unsigned char uuid[16];
+ char *absname = NULL;
+ int islnk = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = -1;
@@ -561,8 +588,10 @@ void main_mkfs(int argc, char *argv[])
}
if (!sdp->override) {
- printf( _("This will destroy any data on %s.\n"), sdp->device_name);
- check_dev_content(sdp->device_name);
+ islnk = is_symlink(sdp->device_name, &absname);
+ printf(_("This will destroy any data on %s.\n"), islnk ? absname : sdp->device_name);
+ check_dev_content(islnk ? absname : sdp->device_name);
+ free(absname);
are_you_sure();
}
--
1.7.7.6
reply other threads:[~2012-06-21 13:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1340285438-12445-1-git-send-email-anprice@redhat.com \
--to=anprice@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).