Re: [lxc-devel] lxc-copy isn't operable in '--snapshot' mode + LVM thin provisioning

2016-04-13 Thread Thomas Tanaka

Hi Vitaliy,

Which kernel are you using with OL7.2 ?

On 4/13/2016 5:16 AM, Vitaliy Baskoff wrote:

Hi All,

ENV: OracleLinux 7.2 + rpm built using .spec from source tarball

sudo lxc-copy --version
2.0.0

lxc-copy fails to copy base container on top of LVM thin provisioned 
volume.


---

STR:
0. sudo lxc-create --name=template --bdev=lvm --vgname=lxdata 
--thinpool=lxpool --fssize=15G --template=./template/lxc-lxsys.sh -- 
--target-mr=55.0 --storage-url=ftp://md.intra/
1. sudo lxc-copy --name='template' --newname='config+log' --snapshot 
-B lvm --logpriority='DEBUG' --logfile='./copy.log'


Logical volume "config+log" created.
lxc-copy: bdev/bdev.c: mount_unknown_fs: 780 failed to determine fs 
type for '/dev/lxdata/config+log'
File descriptor 4 (/run/lxc/lock/var/lib/lxc/.config+log) leaked on 
lvremove invocation. Parent PID 7448: lxc-copy

  Logical volume "config+log" successfully removed
clone failed

---

Please advice.

--
Best regards,
Vitaliy Baskoff
Baks'-Laboratory, Founder/System Administrator
baks-lab.org.ua 


___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


--
Regards,

Thomas

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


Re: [lxc-devel] mounting mqueue in a user namespace

2016-03-11 Thread Thomas Tanaka


On 3/11/2016 3:07 PM, Serge Hallyn wrote:

Quoting Thomas Tanaka (thomas.tan...@oracle.com):

On 3/10/2016 4:18 PM, Serge Hallyn wrote:

Quoting Thomas Tanaka (thomas.tan...@oracle.com):

Hi,

This question might not be specific to lxc/lxd but containers in
general, I hope that is okay.
I have a process created using clone with the following flags
(CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUSER).
The process then try to mount the mqueue filesystem (mount -t mqueue
mqueue /dev/mqueue).
However, the mounted mqueue fs has inode->i_uid = 0, instead of our
ns uid e.g 1. Is this expected ?
For other e.g tmpfs the inode->i_uid is properly set to our ns uid.

Doesn't happen for me.  As simplest example, if I

lxc-usernsexec
# lxc-unshare -s 'IPC|MOUNT' bash
## mount -t mqueue mqueue /mnt
## touch /mnt; ls -ld /mnt; ls -l /mnt

I see everything owned by my namespaced root user, 'root' in my shell.

Right, maybe my understanding is not correct.
So maybe the question should be phrased in such a way, why does a
newly clone() process with CLONE_NEWIPC|CLONE_NEWNS|CLONE_NEWUSER
does not seem to perfom switch_task_namespaces() ?
The observation here is, yes inside of the userns it is owned by
root, but outside of it, i.e in the 'global' ns shouldn't it be

How are you viewing it from the outside?  You'll need to go
through /proc/pid/root/dev/mqueue, else you're look at the
host's mqueue mount right?
Yeah, so I instrumented the kernel (~4.1.12) to print the value of 
inode->i_uid, at mqueue_fill_super() (ipc/mqueue.c),

so with every mount i could see the value of inode->i_uid from the log.

Thanks.



owned by the 'mapped id' e.g 1, instead of 0 ?
Instead, for the mqueue fs, we need to do a unshare(CLONE_NEWIPC)
prior to mounting mqueue, so that the 'global' ns inode->i_uid will
be correctly set to the 'mapped id'.

Thank you for taking time to answer, really appreciate it!


___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

--
Regards,

Thomas

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


--
Regards,

Thomas

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


Re: [lxc-devel] mounting mqueue in a user namespace

2016-03-11 Thread Thomas Tanaka


On 3/10/2016 4:18 PM, Serge Hallyn wrote:

Quoting Thomas Tanaka (thomas.tan...@oracle.com):

Hi,

This question might not be specific to lxc/lxd but containers in
general, I hope that is okay.
I have a process created using clone with the following flags
(CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUSER).
The process then try to mount the mqueue filesystem (mount -t mqueue
mqueue /dev/mqueue).
However, the mounted mqueue fs has inode->i_uid = 0, instead of our
ns uid e.g 1. Is this expected ?
For other e.g tmpfs the inode->i_uid is properly set to our ns uid.

Doesn't happen for me.  As simplest example, if I

lxc-usernsexec
# lxc-unshare -s 'IPC|MOUNT' bash
## mount -t mqueue mqueue /mnt
## touch /mnt; ls -ld /mnt; ls -l /mnt

I see everything owned by my namespaced root user, 'root' in my shell.

Right, maybe my understanding is not correct.
So maybe the question should be phrased in such a way, why does a newly 
clone() process with CLONE_NEWIPC|CLONE_NEWNS|CLONE_NEWUSER does not 
seem to perfom switch_task_namespaces() ?
The observation here is, yes inside of the userns it is owned by root, 
but outside of it, i.e in the 'global' ns shouldn't it be owned by the 
'mapped id' e.g 1, instead of 0 ?
Instead, for the mqueue fs, we need to do a unshare(CLONE_NEWIPC) prior 
to mounting mqueue, so that the 'global' ns inode->i_uid will be 
correctly set to the 'mapped id'.


Thank you for taking time to answer, really appreciate it!


___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


--
Regards,

Thomas

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] mounting mqueue in a user namespace

2016-03-09 Thread Thomas Tanaka

Hi,

This question might not be specific to lxc/lxd but containers in 
general, I hope that is okay.
I have a process created using clone with the following flags 
(CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUSER).
The process then try to mount the mqueue filesystem (mount -t mqueue 
mqueue /dev/mqueue).
However, the mounted mqueue fs has inode->i_uid = 0, instead of our ns 
uid e.g 1. Is this expected ?

For other e.g tmpfs the inode->i_uid is properly set to our ns uid.

Thanks in advance.

--
Regards,

Thomas

___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [PATCH v2] Fix btrfs bus error on sparc on snapshot delete

2016-01-14 Thread Thomas Tanaka
The following patch fixes memory alignment and endianness
issue while doing a snapshot deletion with btrfs as a
backing store on platform such as sparc.

The implementation is taken from btrfs-progs.

Changes since v1:
- include  for bswap definition
- include defined function name as a comment above BTRFS_SETGET_STACK_FUNCS

Signed-off-by: Thomas Tanaka 
---
 src/lxc/bdev/lxcbtrfs.c |   28 +++-
 src/lxc/bdev/lxcbtrfs.h |   45 +
 2 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/src/lxc/bdev/lxcbtrfs.c b/src/lxc/bdev/lxcbtrfs.c
index 2db7c87..0f8c1fc 100644
--- a/src/lxc/bdev/lxcbtrfs.c
+++ b/src/lxc/bdev/lxcbtrfs.c
@@ -565,7 +565,7 @@ static int btrfs_recursive_destroy(const char *path)
int fd;
struct btrfs_ioctl_search_args args;
struct btrfs_ioctl_search_key *sk = &args.key;
-   struct btrfs_ioctl_search_header *sh;
+   struct btrfs_ioctl_search_header sh;
struct btrfs_root_ref *ref;
struct my_btrfs_tree *tree;
int ret, i;
@@ -573,6 +573,7 @@ static int btrfs_recursive_destroy(const char *path)
int name_len;
char *name;
char *tmppath;
+   u64 dir_id;
 
fd = open(path, O_RDONLY);
if (fd < 0) {
@@ -624,21 +625,22 @@ static int btrfs_recursive_destroy(const char *path)
 
off = 0;
for (i = 0; i < sk->nr_items; i++) {
-   sh = (struct btrfs_ioctl_search_header *)(args.buf + 
off);
-   off += sizeof(*sh);
+   memcpy(&sh, args.buf + off, sizeof(sh));
+   off += sizeof(sh);
/*
 * A backref key with the name and dirid of the parent
 * comes followed by the reoot ref key which has the
 * name of the child subvol in question.
 */
-   if (sh->objectid != root_id && sh->type == 
BTRFS_ROOT_BACKREF_KEY) {
+   if (sh.objectid != root_id && sh.type == 
BTRFS_ROOT_BACKREF_KEY) {
ref = (struct btrfs_root_ref *)(args.buf + off);
-   name_len = ref->name_len;
+   name_len = btrfs_stack_root_ref_name_len(ref);
name = (char *)(ref + 1);
-   tmppath = get_btrfs_subvol_path(fd, sh->offset,
-   ref->dirid, name, name_len);
-   if (!add_btrfs_tree_node(tree, sh->objectid,
-   sh->offset, name,
+   dir_id = btrfs_stack_root_ref_dirid(ref);
+   tmppath = get_btrfs_subvol_path(fd, sh.offset,
+   dir_id, name, name_len);
+   if (!add_btrfs_tree_node(tree, sh.objectid,
+   sh.offset, name,
name_len, tmppath)) {
ERROR("Out of memory");
free_btrfs_tree(tree);
@@ -648,15 +650,15 @@ static int btrfs_recursive_destroy(const char *path)
}
free(tmppath);
}
-   off += sh->len;
+   off += sh.len;
 
/*
 * record the mins in sk so we can make sure the
 * next search doesn't repeat this root
 */
-   sk->min_objectid = sh->objectid;
-   sk->min_type = sh->type;
-   sk->min_offset = sh->offset;
+   sk->min_objectid = sh.objectid;
+   sk->min_type = sh.type;
+   sk->min_offset = sh.offset;
}
sk->nr_items = 4096;
sk->min_offset++;
diff --git a/src/lxc/bdev/lxcbtrfs.h b/src/lxc/bdev/lxcbtrfs.h
index e0adb7a..3b2742f 100644
--- a/src/lxc/bdev/lxcbtrfs.h
+++ b/src/lxc/bdev/lxcbtrfs.h
@@ -28,6 +28,7 @@
 #include  /* __le64, __l32 ... */
 #include 
 #include 
+#include 
 
 typedef uint8_t u8;
 typedef uint16_t u16;
@@ -317,6 +318,50 @@ struct btrfs_ioctl_ino_lookup_args {
 #define BTRFS_LAST_FREE_OBJECTID -256ULL
 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
 
+/*
+ * The followings are macro for correctly getting member of
+ * structures in both low and big endian platforms as per
+ * btrfs-progs
+ */
+#ifdef __CHECKER__
+#define __force__attribute__((force))
+#else
+#define __force
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+

[lxc-devel] [PATCH] Fix btrfs bus error on sparc on snapshot delete

2016-01-14 Thread Thomas Tanaka
The following patch fixes memory alignment and endianness
issue while doing a snapshot deletion with btrfs as a
backing store on platform such as sparc.

The implementation is taken from btrfs-progs.

Signed-off-by: Thomas Tanaka 
---
 src/lxc/bdev/lxcbtrfs.c |   28 +++-
 src/lxc/bdev/lxcbtrfs.h |   39 +++
 2 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/src/lxc/bdev/lxcbtrfs.c b/src/lxc/bdev/lxcbtrfs.c
index 2db7c87..0f8c1fc 100644
--- a/src/lxc/bdev/lxcbtrfs.c
+++ b/src/lxc/bdev/lxcbtrfs.c
@@ -565,7 +565,7 @@ static int btrfs_recursive_destroy(const char *path)
int fd;
struct btrfs_ioctl_search_args args;
struct btrfs_ioctl_search_key *sk = &args.key;
-   struct btrfs_ioctl_search_header *sh;
+   struct btrfs_ioctl_search_header sh;
struct btrfs_root_ref *ref;
struct my_btrfs_tree *tree;
int ret, i;
@@ -573,6 +573,7 @@ static int btrfs_recursive_destroy(const char *path)
int name_len;
char *name;
char *tmppath;
+   u64 dir_id;
 
fd = open(path, O_RDONLY);
if (fd < 0) {
@@ -624,21 +625,22 @@ static int btrfs_recursive_destroy(const char *path)
 
off = 0;
for (i = 0; i < sk->nr_items; i++) {
-   sh = (struct btrfs_ioctl_search_header *)(args.buf + 
off);
-   off += sizeof(*sh);
+   memcpy(&sh, args.buf + off, sizeof(sh));
+   off += sizeof(sh);
/*
 * A backref key with the name and dirid of the parent
 * comes followed by the reoot ref key which has the
 * name of the child subvol in question.
 */
-   if (sh->objectid != root_id && sh->type == 
BTRFS_ROOT_BACKREF_KEY) {
+   if (sh.objectid != root_id && sh.type == 
BTRFS_ROOT_BACKREF_KEY) {
ref = (struct btrfs_root_ref *)(args.buf + off);
-   name_len = ref->name_len;
+   name_len = btrfs_stack_root_ref_name_len(ref);
name = (char *)(ref + 1);
-   tmppath = get_btrfs_subvol_path(fd, sh->offset,
-   ref->dirid, name, name_len);
-   if (!add_btrfs_tree_node(tree, sh->objectid,
-   sh->offset, name,
+   dir_id = btrfs_stack_root_ref_dirid(ref);
+   tmppath = get_btrfs_subvol_path(fd, sh.offset,
+   dir_id, name, name_len);
+   if (!add_btrfs_tree_node(tree, sh.objectid,
+   sh.offset, name,
name_len, tmppath)) {
ERROR("Out of memory");
free_btrfs_tree(tree);
@@ -648,15 +650,15 @@ static int btrfs_recursive_destroy(const char *path)
}
free(tmppath);
}
-   off += sh->len;
+   off += sh.len;
 
/*
 * record the mins in sk so we can make sure the
 * next search doesn't repeat this root
 */
-   sk->min_objectid = sh->objectid;
-   sk->min_type = sh->type;
-   sk->min_offset = sh->offset;
+   sk->min_objectid = sh.objectid;
+   sk->min_type = sh.type;
+   sk->min_offset = sh.offset;
}
sk->nr_items = 4096;
sk->min_offset++;
diff --git a/src/lxc/bdev/lxcbtrfs.h b/src/lxc/bdev/lxcbtrfs.h
index e0adb7a..4ea2b4a 100644
--- a/src/lxc/bdev/lxcbtrfs.h
+++ b/src/lxc/bdev/lxcbtrfs.h
@@ -317,6 +317,45 @@ struct btrfs_ioctl_ino_lookup_args {
 #define BTRFS_LAST_FREE_OBJECTID -256ULL
 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
 
+/* The followings are macro for correctly getting member of structures
+ * in both low and big endian platforms as per btrfs-progs 
+ */
+#ifdef __CHECKER__
+#define __force__attribute__((force))
+#else
+#define __force
+#endif
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define cpu_to_le64(x) ((__force __le64)(u64)(bswap_64(x)))
+#define le64_to_cpu(x) ((__force u64)(__le64)(bswap_64(x)))
+#define cpu_to_le32(x) ((__force __le32)(u32)(bswap_32(x)))
+#define le32_to_cpu(x) ((__force u32)(__le32)(bswap_32(x)))
+#define cpu_to_le16(x) ((__forc