Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tbird committed Sep 29, 2015
1 parent 472faab commit 25b2f57
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
# docker-volume-rbd
A Docker volume driver for RBD

##### Sample
Client side:
```
core@core-1 ~ $ docker run -it --volume-driver rbd -v foo:/foo alpine /bin/sh -c "echo -n 'hello ' > /foo/hw.txt"
core@core-1 ~ $ docker run -it --volume-driver rbd -v foo:/foo alpine /bin/sh -c "echo world >> /foo/hw.txt"
core@core-1 ~ $ docker run -it --volume-driver rbd -v foo:/foo alpine cat /foo/hw.txt
hello world
```
Server side:
```
core@core-1 ~ $ sudo ./docker-volume-rbd
2015/09/29 13:52:23 [Init] INFO volume root is /var/lib/docker/volumes/rbd
2015/09/29 13:52:23 [Init] INFO loading RBD kernel module...
2015/09/29 13:52:23 [Init] INFO listening on /var/run/docker/plugins/rbd.sock
2015/09/29 13:52:30 [Create] INFO image does not exists. Creating it now...
2015/09/29 13:52:33 [Mount] INFO locking image foo
2015/09/29 13:52:33 [Mount] INFO mapping image foo
2015/09/29 13:52:34 [Mount] INFO creating /var/lib/docker/volumes/rbd/rbd/foo
2015/09/29 13:52:34 [Mount] INFO mounting device /dev/rbd0
2015/09/29 13:52:34 [Unmount] INFO unmounting device /dev/rbd0
2015/09/29 13:52:34 [Unmount] INFO unmapping image foo
2015/09/29 13:52:34 [Unmount] INFO unlocking image foo
2015/09/29 13:52:40 [Mount] INFO locking image foo
2015/09/29 13:52:40 [Mount] INFO mapping image foo
2015/09/29 13:52:41 [Mount] INFO creating /var/lib/docker/volumes/rbd/rbd/foo
2015/09/29 13:52:41 [Mount] INFO mounting device /dev/rbd0
2015/09/29 13:52:41 [Unmount] INFO unmounting device /dev/rbd0
2015/09/29 13:52:41 [Unmount] INFO unmapping image foo
2015/09/29 13:52:42 [Unmount] INFO unlocking image foo
2015/09/29 13:52:48 [Mount] INFO locking image foo
2015/09/29 13:52:48 [Mount] INFO mapping image foo
2015/09/29 13:52:49 [Mount] INFO creating /var/lib/docker/volumes/rbd/rbd/foo
2015/09/29 13:52:49 [Mount] INFO mounting device /dev/rbd0
2015/09/29 13:52:49 [Unmount] INFO unmounting device /dev/rbd0
2015/09/29 13:52:49 [Unmount] INFO unmapping image foo
2015/09/29 13:52:49 [Unmount] INFO unlocking image foo
```

##### CoreOS
If you are a CoreOS user (like me) you must provide a way to run the `rbd` command.
I have my Ceph config in `/etc/ceph` so I can do this:
Expand Down
9 changes: 5 additions & 4 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ func initDriver(volRoot, defPool, defFsType string, defSize int) rbdDriver {
for _, i := range commands {
cmd[i], err = exec.LookPath(i)
if err != nil {
log.Fatal("[Init] ERROR Make sure binary %s is in your PATH", i)
log.Fatal("[Init] ERROR make sure binary %s is in your PATH", i)
}
}

// Load RBD kernel module
log.Printf("[Init] INFO loading RBD kernel module...")
if err = exec.Command(cmd["modprobe"], "rbd").Run(); err != nil {
log.Fatal("[Init] ERROR Unable to load RBD kernel module")
log.Fatal("[Init] ERROR unable to load RBD kernel module")
}

// Initialize the struct
Expand Down Expand Up @@ -123,13 +124,13 @@ func (d *rbdDriver) Create(r dkvolume.Request) dkvolume.Response {
// Check if volume already exists
mountpoint := filepath.Join(d.volRoot, pool, name)
if _, found := d.volumes[mountpoint]; found {
log.Println("[Create] INFO Volume is already in known mounts: " + mountpoint)
log.Println("[Create] INFO volume is already in known mounts: " + mountpoint)
return dkvolume.Response{}
}

// Create RBD image if not exists
if exists, err := d.imageExists(pool, name); !exists && err == nil {
log.Println("[Create] INFO Image does not exists. Creating it now...")
log.Println("[Create] INFO image does not exists. Creating it now...")
if err = d.createImage(pool, name, d.defFsType, size); err != nil {
return dkvolume.Response{Err: err.Error()}
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func usage() {
func main() {

// Request handler with a driver implementation
log.Printf("[Init] INFO Volume root is %s\n", *volRoot)
log.Printf("[Init] INFO volume root is %s\n", *volRoot)
d := initDriver(*volRoot, *defPool, *defFsType, *defSize)
h := dkvolume.NewHandler(&d)

// Listen for requests in a unix socket:
log.Printf("[Init] INFO Listening on %s\n", socket)
log.Printf("[Init] INFO listening on %s\n", socket)
fmt.Println(h.ServeUnix("", socket))
}

0 comments on commit 25b2f57

Please sign in to comment.