Skip to content

Commit 24524a7

Browse files
committed
PoC
0 parents  commit 24524a7

File tree

434 files changed

+205356
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

434 files changed

+205356
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea/
2+
.vagrant/
3+
4+
docker-volume-loopback
5+
6+
plugin/rootfs
7+
tmp

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# build
2+
FROM golang:1.11-alpine as builder
3+
RUN apk --no-cache add make
4+
ADD ./ /go/src/github.com/ashald/docker-volume-loopback/
5+
WORKDIR /go/src/github.com/ashald/docker-volume-loopback
6+
RUN make build && \
7+
mv ./docker-volume-loopback /usr/bin/
8+
9+
10+
# package
11+
FROM alpine
12+
RUN apk --no-cache add e2fsprogs
13+
COPY --from=builder /usr/bin/docker-volume-loopback /docker-volume-loopback
14+
CMD [ "/docker-volume-loopback" ]

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
VERSION := 0
2+
ROOTFS_IMAGE := ashald/docker-volume-loopback-rootfs
3+
ROOTFS_CONTAINER := rootfs
4+
PLUGIN_NAME := docker-volume-loopback
5+
PLUGIN_FULL_NAME := ashald/docker-volume-loopback
6+
7+
build:
8+
GOOS=linux GOARCH=amd64 go build -o $(PLUGIN_NAME)
9+
10+
rootfs-image:
11+
docker build -t $(ROOTFS_IMAGE) .
12+
13+
rootfs: rootfs-image
14+
docker rm -vf $(ROOTFS_CONTAINER) || true
15+
docker create --name $(ROOTFS_CONTAINER) $(ROOTFS_IMAGE) || true
16+
mkdir -p plugin/rootfs
17+
rm -rf plugin/rootfs/*
18+
docker export $(ROOTFS_CONTAINER) | tar -x -C plugin/rootfs
19+
docker rm -vf $(ROOTFS_CONTAINER)
20+
21+
22+
plugin: rootfs
23+
docker plugin disable $(PLUGIN_NAME) || true
24+
docker plugin rm --force $(PLUGIN_NAME) || true
25+
docker plugin create $(PLUGIN_NAME) ./plugin
26+
docker plugin enable $(PLUGIN_NAME)
27+
28+
29+
plugin-push: rootfs
30+
docker plugin rm --force $(PLUGIN_FULL_NAME) || true
31+
docker plugin create $(PLUGIN_FULL_NAME) ./plugin
32+
docker plugin create $(PLUGIN_FULL_NAME):$(VERSION) ./plugin
33+
docker plugin push $(PLUGIN_FULL_NAME)
34+
docker plugin push $(PLUGIN_FULL_NAME):$(VERSION)
35+
36+
37+
.PHONY: build rootfs-image rootfs plugin plugin-push

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<h1 align="center">xfsvol 📂 </h1>
2+
3+
<h5 align="center">Docker Volume Plugin for managing local XFS-based volumes</h5>
4+
5+
<br/>
6+
7+
[![Build Status](https://travis-ci.org/cirocosta/xfsvol.svg?branch=master)](https://travis-ci.org/cirocosta/xfsvol)
8+
9+
## Quickstart
10+
11+
1. Create a mountpoint at `/mnt/xfs` and a directory `/mnt/xfs/volumes`.
12+
13+
For testing purposes this mountpoint can be a loopback device (note: use a loopback device for testing purposes only).
14+
15+
```sh
16+
sudo dd if=/dev/zero of=/xfs.1G bs=1M count=1024
17+
sudo losetup /dev/loop0 /xfs.1G
18+
sudo mkfs -t xfs -n ftype=1 /dev/loop0
19+
sudo mkdir -p /mnt/xfs/volumes
20+
sudo mount /dev/loop0 /mnt/xfs -o pquota
21+
```
22+
23+
2. Install the plugin
24+
25+
```
26+
docker plugin install \
27+
--grant-all-permissions \
28+
--alias xfsvol \
29+
cirocosta/xfsvol
30+
31+
docker plugin ls
32+
ID NAME DESCRIPTION ENABLED
33+
06545b643c6a xfsvol:latest Docker plugin to manage XFS-mounted volumes true
34+
```
35+
36+
3. Create a named volume
37+
38+
```
39+
docker volume create \
40+
--driver xfsvol \
41+
--opt size=10M \
42+
myvolume1
43+
```
44+
45+
4. Run a container with the volume attached
46+
47+
```
48+
docker run -it \
49+
-v myvolume1:/myvolume1 \
50+
alpine /bin/sh
51+
52+
dd if=/dev/zero of=/myvolume1/file bs=1M count=100
53+
(fail!)
54+
```
55+
56+
5. Check the volumes list
57+
58+
```
59+
docker volume ls
60+
DRIVER VOLUME NAME
61+
xfsvol:latest myvolume1 (1.004MB)
62+
local dockerdev-go-pkg-cache-gopath
63+
local dockerdev-go-pkg-cache-goroot-linux_amd64
64+
local dockerdev-go-pkg-cache-goroot-linux_amd64_netgo
65+
```
66+
67+
and the `xfsvolctl` utility:
68+
69+
```
70+
sudo /usr/bin/xfsvolctl ls --root /mnt/xfs/volumes/
71+
NAME QUOTA
72+
ciro 1.004 MB
73+
```
74+
75+
## `xfsvolctl`
76+
77+
This tool is made to help inspect the project quotas created under a given root path as well as create/delete others. It's usage is documented under `--help`:
78+
79+
```
80+
xfsvolctl --help
81+
NAME:
82+
xfsvolctl - Controls the 'xfsvol' volume plugin
83+
84+
USAGE:
85+
xfsvolctl [global options] command [command options] [arguments...]
86+
87+
VERSION:
88+
0.0.0
89+
90+
COMMANDS:
91+
ls Lists the volumes managed by 'xfsvol' plugin
92+
create Creates a volume with XFS project quota enforcement
93+
delete Deletes a volume managed by 'xfsvol' plugin
94+
help, h Shows a list of commands or help for one command
95+
96+
GLOBAL OPTIONS:
97+
--help, -h show help
98+
--version, -v print the version
99+
```
100+
101+
### Under the hood
102+
103+
104+
```
105+
$ sudo mkdir -p /mnt/xfs/tmp/bbb
106+
$ sudo strace -f xfsvolctl create \
107+
--root /mnt/xfs/tmp/bbb \
108+
--name ccc \
109+
--size 1024 \
110+
--inode 1024
111+
112+
stat("/mnt/xfs/tmp/bbb", {st_mode=S_IFDIR|0755, st_size=6, ...}) = 0
113+
unlinkat(AT_FDCWD, "/mnt/xfs/tmp/bbb/backingFsBlockDev", 0) = -1 ENOENT (No such file or directory)
114+
mknodat(AT_FDCWD, "/mnt/xfs/tmp/bbb/backingFsBlockDev", S_IFBLK|0600, makedev(7, 0)) = 0
115+
quotactl(Q_XSETQLIM|PRJQUOTA, "/mnt/xfs/tmp/bbb/backingFsBlockDev", 1, {version=1, flags=XFS_PROJ_QUOTA, fieldmask=0xc, id=1, blk_hardlimit=0, blk_softlimit=0, ino_hardlimit=0, ino_softlimit=0, bcount=0, icount=0, ...}) = 0
116+
...
117+
mkdirat(AT_FDCWD, "/mnt/xfs/tmp/bbb/ccc", 0755) = 0
118+
open("/mnt/xfs/tmp/bbb/ccc", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3
119+
fstat(3, {st_mode=S_IFDIR|0755, st_size=6, ...}) = 0
120+
ioctl(3, FS_IOC_FSGETXATTR, 0xc4201a95e4) = 0
121+
ioctl(3, FS_IOC_FSSETXATTR, 0xc4201a95e4) = 0
122+
123+
quotactl(Q_XSETQLIM|PRJQUOTA, "/mnt/xfs/tmp/bbb/backingFsBlockDev", 2, {version=1, flags=XFS_PROJ_QUOTA, fieldmask=0xc, id=2, blk_hardlimit=2, blk_softlimit=2, ino_hardlimit=1024, ino_softlimit=1024, bcount=0, icount=0, ...}) = 0
124+
[pid 6833] ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
125+
126+
127+
// retrieving (ls)
128+
129+
[pid 8609] quotactl(Q_XGETQUOTA|PRJQUOTA, "/mnt/xfs/tmp/ddd/backingFsBlockDev", 2, {version=1, flags=XFS_PROJ_QUOTA, fieldmask=0, id=2, blk_hardlimit=8, blk_softlimit=8, ino_hardlimit=0, ino_softlimit=0, bcount=8, icount=104, ...}) = 0
130+
131+
132+
```
133+

0 commit comments

Comments
 (0)