Skip to content

Commit

Permalink
lxcbtrfs.{c,h} rework declarations and definitions
Browse files Browse the repository at this point in the history
Declare

	- btrfs_same_fs();
	- btrfs_snapshot();

extern instead of static in lxcbtrfs.h. They are defined in lxcbtrfs.c.

Forward declare/put

	- struct bdev; /* defined in bdev.h */
	- struct bdev_specs; /* defined in lxccontainer.h */
	- struct lxc_conf; /* defined conf.h */

as incomplete types in lxcbtrfs.h so that functions declared and defined in
lxcbtrfs.{c,h} have access to it.

Declare

	- dir_new_path();

in lxcbtrfs.c. It is defined in lxccontainer.c.

Move definition of struct

	- struct rsync_data_char;

from bdev.c to bdev.h because the functions in lxcbtrfs.{c,h} need to access it.

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
  • Loading branch information
Christian Brauner committed Dec 28, 2015
1 parent f2e50c4 commit 93d4475
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/lxc/bdev/bdev.c
Expand Up @@ -77,11 +77,6 @@

lxc_log_define(bdev, lxc);

struct rsync_data_char {
char *src;
char *dest;
};

/* the bulk of this needs to become a common helper */
int do_rsync(const char *src, const char *dest)
{
Expand Down Expand Up @@ -110,7 +105,7 @@ int do_rsync(const char *src, const char *dest)

/* the bulk of this needs to become a common helper */
char *dir_new_path(char *src, const char *oldname, const char *name,
const char *oldpath, const char *lxcpath)
const char *oldpath, const char *lxcpath)
{
char *ret, *p, *p2;
int l1, l2, nlen;
Expand Down
5 changes: 5 additions & 0 deletions src/lxc/bdev/bdev.h
Expand Up @@ -134,4 +134,9 @@ void detach_block_device(struct lxc_conf *conf);

bool rootfs_is_blockdev(struct lxc_conf *conf);

struct rsync_data_char {
char *src;
char *dest;
};

#endif // __LXC_BDEV_H
18 changes: 16 additions & 2 deletions src/lxc/bdev/lxcbtrfs.c
Expand Up @@ -22,15 +22,29 @@
*/

#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "bdev.h"
#include "log.h"
#include "lxcbtrfs.h"
#include "utils.h"

lxc_log_define(btrfs, lxc);

/* defined in lxccontainer.c: needs to become common helper */
extern char *dir_new_path(char *src, const char *oldname, const char *name,
const char *oldpath, const char *lxcpath);

/*
* Return the full path of objid under dirid. Let's say dirid is
* /lxc/c1/rootfs, and objid is /lxc/c1/rootfs/a/b/c. Then we will
Expand Down Expand Up @@ -213,7 +227,7 @@ static int btrfs_subvolume_create(const char *path)
return ret;
}

static int btrfs_same_fs(const char *orig, const char *new)
int btrfs_same_fs(const char *orig, const char *new)
{
int fd_orig = -1, fd_new = -1, ret = -1;
struct btrfs_ioctl_fs_info_args orig_args, new_args;
Expand Down Expand Up @@ -254,7 +268,7 @@ static int btrfs_same_fs(const char *orig, const char *new)
return ret;
}

static int btrfs_snapshot(const char *orig, const char *new)
int btrfs_snapshot(const char *orig, const char *new)
{
int fd = -1, fddst = -1, ret = -1;
struct btrfs_ioctl_vol_args_v2 args;
Expand Down
13 changes: 13 additions & 0 deletions src/lxc/bdev/lxcbtrfs.h
Expand Up @@ -24,8 +24,10 @@
#ifndef __LXC_BTRFS_H
#define __LXC_BTRFS_H

#define _GNU_SOURCE
#include <stdbool.h>
#include <stdint.h>
#include <sys/prctl.h>

typedef uint8_t u8;
typedef uint16_t u16;
Expand Down Expand Up @@ -315,6 +317,15 @@ struct btrfs_ioctl_ino_lookup_args {
#define BTRFS_LAST_FREE_OBJECTID -256ULL
#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL

/* defined in bdev.h */
struct bdev;

/* defined in lxccontainer.h */
struct bdev_specs;

/* defined conf.h */
struct lxc_conf;

struct mytree_node {
u64 objid;
u64 parentid;
Expand Down Expand Up @@ -349,5 +360,7 @@ char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
int btrfs_list_get_path_rootid(int fd, u64 *treeid);
bool is_btrfs_fs(const char *path);
bool btrfs_try_remove_subvol(const char *path);
int btrfs_same_fs(const char *orig, const char *new);
int btrfs_snapshot(const char *orig, const char *new);

#endif // __LXC_BTRFS_H

0 comments on commit 93d4475

Please sign in to comment.