forked from Mirrors/btrfs-progs
btrfs-progs: use libbtrfsutil for sync ioctls
Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>master
parent
3e76e9b676
commit
ec7251486d
|
@ -28,6 +28,8 @@
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <btrfsutil.h>
|
||||||
|
|
||||||
#include "kerncompat.h"
|
#include "kerncompat.h"
|
||||||
#include "ctree.h"
|
#include "ctree.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -813,25 +815,16 @@ static const char * const cmd_filesystem_sync_usage[] = {
|
||||||
|
|
||||||
static int cmd_filesystem_sync(int argc, char **argv)
|
static int cmd_filesystem_sync(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int fd, res;
|
enum btrfs_util_error err;
|
||||||
char *path;
|
|
||||||
DIR *dirstream = NULL;
|
|
||||||
|
|
||||||
clean_args_no_options(argc, argv, cmd_filesystem_sync_usage);
|
clean_args_no_options(argc, argv, cmd_filesystem_sync_usage);
|
||||||
|
|
||||||
if (check_argc_exact(argc - optind, 1))
|
if (check_argc_exact(argc - optind, 1))
|
||||||
usage(cmd_filesystem_sync_usage);
|
usage(cmd_filesystem_sync_usage);
|
||||||
|
|
||||||
path = argv[optind];
|
err = btrfs_util_sync(argv[optind]);
|
||||||
|
if (err) {
|
||||||
fd = btrfs_open_dir(path, &dirstream, 1);
|
error_btrfs_util(err);
|
||||||
if (fd < 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
res = ioctl(fd, BTRFS_IOC_SYNC);
|
|
||||||
close_file_or_dir(fd, dirstream);
|
|
||||||
if( res < 0 ){
|
|
||||||
error("sync ioctl failed on '%s': %m", path);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include <btrfsutil.h>
|
||||||
|
|
||||||
#include "ctree.h"
|
#include "ctree.h"
|
||||||
#include "ioctl.h"
|
#include "ioctl.h"
|
||||||
|
|
||||||
|
@ -299,6 +301,7 @@ static int cmd_qgroup_show(int argc, char **argv)
|
||||||
int filter_flag = 0;
|
int filter_flag = 0;
|
||||||
unsigned unit_mode;
|
unsigned unit_mode;
|
||||||
int sync = 0;
|
int sync = 0;
|
||||||
|
enum btrfs_util_error err;
|
||||||
|
|
||||||
struct btrfs_qgroup_comparer_set *comparer_set;
|
struct btrfs_qgroup_comparer_set *comparer_set;
|
||||||
struct btrfs_qgroup_filter_set *filter_set;
|
struct btrfs_qgroup_filter_set *filter_set;
|
||||||
|
@ -372,9 +375,10 @@ static int cmd_qgroup_show(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
ret = ioctl(fd, BTRFS_IOC_SYNC);
|
err = btrfs_util_sync_fd(fd);
|
||||||
if (ret < 0)
|
if (err)
|
||||||
warning("sync ioctl failed on '%s': %m", path);
|
warning("sync ioctl failed on '%s': %s", path,
|
||||||
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_flag) {
|
if (filter_flag) {
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
#include <linux/magic.h>
|
#include <linux/magic.h>
|
||||||
|
|
||||||
|
#include <btrfsutil.h>
|
||||||
|
|
||||||
#include "kerncompat.h"
|
#include "kerncompat.h"
|
||||||
#include "ioctl.h"
|
#include "ioctl.h"
|
||||||
#include "qgroup.h"
|
#include "qgroup.h"
|
||||||
|
@ -226,12 +228,18 @@ out:
|
||||||
|
|
||||||
static int wait_for_commit(int fd)
|
static int wait_for_commit(int fd)
|
||||||
{
|
{
|
||||||
int ret;
|
enum btrfs_util_error err;
|
||||||
|
uint64_t transid;
|
||||||
|
|
||||||
ret = ioctl(fd, BTRFS_IOC_START_SYNC, NULL);
|
err = btrfs_util_start_sync_fd(fd, &transid);
|
||||||
if (ret < 0)
|
if (err)
|
||||||
return ret;
|
return -1;
|
||||||
return ioctl(fd, BTRFS_IOC_WAIT_SYNC, NULL);
|
|
||||||
|
err = btrfs_util_wait_sync_fd(fd, transid);
|
||||||
|
if (err)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const cmd_subvol_delete_usage[] = {
|
static const char * const cmd_subvol_delete_usage[] = {
|
||||||
|
@ -932,6 +940,7 @@ static int cmd_subvol_find_new(int argc, char **argv)
|
||||||
char *subvol;
|
char *subvol;
|
||||||
u64 last_gen;
|
u64 last_gen;
|
||||||
DIR *dirstream = NULL;
|
DIR *dirstream = NULL;
|
||||||
|
enum btrfs_util_error err;
|
||||||
|
|
||||||
clean_args_no_options(argc, argv, cmd_subvol_find_new_usage);
|
clean_args_no_options(argc, argv, cmd_subvol_find_new_usage);
|
||||||
|
|
||||||
|
@ -955,9 +964,9 @@ static int cmd_subvol_find_new(int argc, char **argv)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
ret = ioctl(fd, BTRFS_IOC_SYNC);
|
err = btrfs_util_sync_fd(fd);
|
||||||
if (ret < 0) {
|
if (err) {
|
||||||
error("sync ioctl failed on '%s': %m", subvol);
|
error_btrfs_util(err);
|
||||||
close_file_or_dir(fd, dirstream);
|
close_file_or_dir(fd, dirstream);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue