From: Anand Jain <Anand.Jain@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/3 v4] btrfs-progs: disable using backup superblock by default
Date: Mon, 18 Mar 2013 11:39:48 +0800 [thread overview]
Message-ID: <51468C84.2060204@oracle.com> (raw)
In-Reply-To: <51434DAC.9000206@redhat.com>
>> # mkfs.btrfs /dev/sdb /dev/sdc -f && mount /dev/sdb /btrfs
>> # ./check-mounted /dev/sdc
>> its btrfs
>> /dev/sdc is currently mounted. Aborting.
>> # dd if=/dev/zero of=/dev/sdc count=8 seek=$(((64 * 1024)/512))
>> # ./check-mounted /dev/sdc
>
> what is "./check-mounted?"
sorry forgot to mention.. check-mounted is small prog it unit-tests
check_mounted() function (Find the diff below.)
>> Not mounted
>> # cat /proc/mounts | egrep btrfs
>> /dev/sdb /btrfs btrfs rw,seclabel,relatime,noacl,space_cache 0 0
>>
>>
>> So we have to set BTRFS_SCAN_BACKUP_SB for check_mounted()
>> But the above scenario is not simple enough to be practical though.
>
> (Seems like a mount check would be best implemented by asking the kernel
> which devices are in use for mounted btrfs filesystems, rather than
> scanning the block devices directly, but maybe that's a different issue.)
>
> I guess I need to stop & think more carefully about this, it seems like
> I am not seeing the whole picture.
>
> The overall goal here is to not discover "btrfs" devices which actually
> only have stale backup superblocks present, right?
>
> The loop in btrfs_read_dev_super() might be ok for verifying backups,
> but it should probably fail outright on the first bad one it finds,
> or at least if the primary is bad; the user would be notified of the
> inconsistency and could take corrective action w/ fsck or whatnot, right?
This logic is not be suitable for the function check_mounted().
The above test case just demonstrates that. This is about btrfs
on multi-dev and we use one dev to mount and another dev to check
if its mounted, now if the primary SB is corrupted on this (latter)
dev we still need to find its mounted by reading from the backup SB,
so setting the BTRFS_SCAN_BACKUP_SB will help.
Thanks, Anand
---------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index d102dee..c97e6b7 100644
--- a/Makefile
+++ b/Makefile
@@ -159,6 +159,10 @@ btrfs-select-super: $(objects) $(libs)
btrfs-select-super.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfs-select-super $(objects)
btrfs-select-super.o $(LDFLAGS) $(LIBS)
+check-mounted: $(objects) $(libs) check-mounted.o
+ @echo " [LD] $@"
+ $(Q)$(CC) $(CFLAGS) -o check-mounted $(objects) check-mounted.o
$(LDFLAGS) $(LIBS)
+
btrfstune: $(objects) $(libs) btrfstune.o
@echo " [LD] $@"
$(Q)$(CC) $(CFLAGS) -o btrfstune $(objects) btrfstune.o
$(LDFLAGS) $(LIBS)
@@ -205,7 +209,7 @@ clean :
@echo "Cleaning"
$(Q)rm -f $(progs) cscope.out *.o .*.d btrfs-convert
btrfs-image btrfs-select-super \
btrfs-zero-log btrfstune dir-test ioctl-test quick-test
send-test btrfs.static btrfsck \
- version.h \
+ version.h check-mounted\
$(libs) $(lib_links)
$(Q)$(MAKE) $(MAKEOPTS) -C man $@
diff --git a/check-mounted.c b/check-mounted.c
new file mode 100644
index 0000000..781edec
--- /dev/null
+++ b/check-mounted.c
@@ -0,0 +1,31 @@
+
+#define _XOPEN_SOURCE 500
+#define _GNU_SOURCE 1
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include "kerncompat.h"
+#include "ctree.h"
+#include "disk-io.h"
+#include "print-tree.h"
+#include "transaction.h"
+#include "list.h"
+#include "version.h"
+#include "utils.h"
+
+int main(int ac, char **av)
+{
+ int ret;
+
+ if((ret = check_mounted(av[optind])) < 0) {
+ fprintf(stderr, "Could not check mount status: %s\n",
strerror(-ret));
+ return ret;
+ } else if(ret) {
+ fprintf(stderr, "%s is currently mounted. Aborting.\n",
av[optind]);
+ return -EBUSY;
+ }
+ printf("Not mounted\n");
+ return 0;
+}
------------------------------------------------------------------------------
prev parent reply other threads:[~2013-03-18 3:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-08 15:24 [PATCH 0/3 v2] flags to access backup SB Anand Jain
2013-03-08 15:24 ` [PATCH 1/3] btrfs-progs: Introduce flag BTRFS_SCAN_REGISTER to replace run_ioctl Anand Jain
2013-03-08 15:24 ` [PATCH 2/3] btrfs-progs: Introduce flag BTRFS_SCAN_BACKUP_SB for btrfs_read_dev_super Anand Jain
2013-03-08 15:25 ` [PATCH 3/3] btrfs-progs: use BTRFS_SCAN_BACKUP_SB flag in btrfs_scan_one_device Anand Jain
2013-03-11 15:03 ` Eric Sandeen
2013-03-11 18:16 ` David Sterba
2013-03-13 11:46 ` Anand Jain
2013-03-14 8:51 ` Anand Jain
2013-03-13 11:44 ` [PATCH 0/3 v3] flags to access backup SB Anand Jain
2013-03-13 11:44 ` [PATCH 1/3 v3] btrfs-progs: Introduce flag BTRFS_SCAN_REGISTER to replace run_ioctl Anand Jain
2013-03-13 11:44 ` [PATCH 2/3 v3] btrfs-progs: Introduce flag BTRFS_SCAN_BACKUP_SB for btrfs_read_dev_super Anand Jain
2013-03-13 11:44 ` [PATCH 3/3 v3] btrfs-progs: disable using backup superblock by default Anand Jain
2013-03-14 3:05 ` [PATCH 0/3 v4] flags to access backup SB Anand Jain
2013-03-14 3:05 ` [PATCH 1/3 v4] btrfs-progs: Introduce flag BTRFS_SCAN_REGISTER to replace run_ioctl Anand Jain
2013-03-14 3:05 ` [PATCH 2/3 v4] btrfs-progs: Introduce flag BTRFS_SCAN_BACKUP_SB for btrfs_read_dev_super Anand Jain
2013-03-14 3:05 ` [PATCH 3/3 v4] btrfs-progs: disable using backup superblock by default Anand Jain
2013-03-14 4:36 ` Eric Sandeen
2013-03-14 8:56 ` Anand Jain
2013-03-14 14:47 ` Eric Sandeen
2013-03-14 14:49 ` Eric Sandeen
2013-03-15 12:03 ` Anand Jain
2013-03-15 16:34 ` Eric Sandeen
2013-03-18 3:39 ` Anand Jain [this message]
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=51468C84.2060204@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=sandeen@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).