2010-10-05 14:14:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2015-06-05 16:02:08 +00:00
|
|
|
#include "kerncompat.h"
|
|
|
|
|
2010-10-05 14:14:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "ctree.h"
|
|
|
|
#include "disk-io.h"
|
|
|
|
#include "transaction.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
2015-06-05 16:02:08 +00:00
|
|
|
__attribute__((noreturn)) static void print_usage(void)
|
2010-10-05 14:14:48 +00:00
|
|
|
{
|
2016-09-03 18:30:50 +00:00
|
|
|
printf("usage: btrfs-zero-log dev\n");
|
2010-10-05 14:14:48 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:28:11 +00:00
|
|
|
int main(int argc, char **argv)
|
2010-10-05 14:14:48 +00:00
|
|
|
{
|
|
|
|
struct btrfs_root *root;
|
2011-11-21 15:27:17 +00:00
|
|
|
struct btrfs_trans_handle *trans;
|
2015-06-05 16:02:08 +00:00
|
|
|
struct btrfs_super_block *sb;
|
2010-10-05 14:14:48 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-03-01 15:28:11 +00:00
|
|
|
set_argv0(argv);
|
2016-03-01 15:29:16 +00:00
|
|
|
if (check_argc_exact(argc - optind, 1))
|
2010-10-05 14:14:48 +00:00
|
|
|
print_usage();
|
|
|
|
|
|
|
|
radix_tree_init();
|
|
|
|
|
2015-06-05 16:02:08 +00:00
|
|
|
printf("WARNING: this utility is deprecated, please use 'btrfs rescue zero-log'\n\n");
|
|
|
|
|
2016-03-01 15:29:16 +00:00
|
|
|
if ((ret = check_mounted(argv[optind])) < 0) {
|
2015-06-05 16:02:08 +00:00
|
|
|
fprintf(stderr, "ERROR: could not check mount status: %s\n", strerror(-ret));
|
2013-09-04 15:22:31 +00:00
|
|
|
goto out;
|
2015-06-05 16:02:08 +00:00
|
|
|
} else if (ret) {
|
2016-03-01 15:29:16 +00:00
|
|
|
fprintf(stderr, "ERROR: %s is currently mounted\n", argv[optind]);
|
2013-09-04 15:22:31 +00:00
|
|
|
ret = -EBUSY;
|
|
|
|
goto out;
|
2010-10-05 14:14:48 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 15:29:16 +00:00
|
|
|
root = open_ctree(argv[optind], 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL);
|
2015-06-05 16:02:08 +00:00
|
|
|
if (!root) {
|
|
|
|
fprintf(stderr, "ERROR: cannot open ctree\n");
|
2010-10-05 14:14:48 +00:00
|
|
|
return 1;
|
2015-06-05 16:02:08 +00:00
|
|
|
}
|
2010-10-05 14:14:48 +00:00
|
|
|
|
2015-06-05 16:02:08 +00:00
|
|
|
sb = root->fs_info->super_copy;
|
|
|
|
printf("Clearing log on %s, previous log_root %llu, level %u\n",
|
2016-03-01 15:29:16 +00:00
|
|
|
argv[optind],
|
2015-06-05 16:02:08 +00:00
|
|
|
(unsigned long long)btrfs_super_log_root(sb),
|
|
|
|
(unsigned)btrfs_super_log_root_level(sb));
|
2011-11-21 15:27:17 +00:00
|
|
|
trans = btrfs_start_transaction(root, 1);
|
2013-03-06 16:32:51 +00:00
|
|
|
btrfs_set_super_log_root(root->fs_info->super_copy, 0);
|
|
|
|
btrfs_set_super_log_root_level(root->fs_info->super_copy, 0);
|
2011-11-21 15:27:17 +00:00
|
|
|
btrfs_commit_transaction(trans, root);
|
2010-10-05 14:14:48 +00:00
|
|
|
close_ctree(root);
|
2013-09-04 15:22:31 +00:00
|
|
|
out:
|
|
|
|
return !!ret;
|
2010-10-05 14:14:48 +00:00
|
|
|
}
|