diff --git a/README.md b/README.md index ebbed31..be77f79 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/driver.go b/driver.go index 3d619c3..4cfee79 100644 --- a/driver.go +++ b/driver.go @@ -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 @@ -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()} } diff --git a/main.go b/main.go index 11af500..ad587fc 100644 --- a/main.go +++ b/main.go @@ -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)) }