Exemplo n.º 1
0
func (d *etcDriver) Create(rq dkvolume.Request) dkvolume.Response {
	var res dkvolume.Response
	if !strings.HasPrefix(rq.Name, "@") {
		return responseErrorString("a etcd path has to start with a @")
	}
	d.mux.Lock()
	defer d.mux.Unlock()

	_, ok := d.mountpoints[rq.Name]
	if ok {
		return res
	}

	pt := d.createPath(rq.Name)
	if err := os.MkdirAll(pt, 0755); err != nil {
		return responseError(fmt.Errorf("cannot mkdir: %s", err))
	}
	rootfs := "/" + d.asEtcdRoot(rq.Name)
	root := pathfs.NewPrefixFileSystem(&d.etcdbackend, rootfs)
	nfs := pathfs.NewPathNodeFs(root, nil)
	server, _, err := nodefs.MountRoot(pt, nfs.Root(), nil)

	if err != nil {
		return responseError(fmt.Errorf("cannot mount root : %s", err))
	}
	es := etcdFuseServer{pt, server, 0}
	d.mountpoints[rq.Name] = &es

	go server.Serve()
	return res
}
Exemplo n.º 2
0
func (fuseFS *fuseFS) newWorkerFS(id string) (*workerFS, error) {
	fs := &workerFS{
		id:     id,
		fuseFS: fuseFS,
		tmpDir: filepath.Join(fuseFS.tmpDir, id),
	}
	fs.state = newWorkerFSState(fs)

	type dirInit struct {
		dst *string
		val string
	}

	fs.rwDir = filepath.Join(fs.tmpDir, "rw")
	if err := os.MkdirAll(fs.rwDir, 0700); err != nil {
		return nil, err
	}

	prefixFS := pathfs.NewPrefixFileSystem(fuseFS.rpcFS, fs.fuseFS.writableRoot)

	fs.annotatingFS = NewAnnotatingFS(prefixFS)

	var err error
	fs.unionFs, err = termitefs.NewMemUnionFs(
		fs.rwDir, fs.annotatingFS)
	if err != nil {
		return nil, err
	}

	fs.rootDir = filepath.Join(fuseFS.mount, id)
	if code := fs.fuseFS.rpcNodeFS.Mount(
		id, fs.unionFs.Root(), nodeFSOptions()); !code.Ok() {
		return nil, errors.New(fmt.Sprintf("submount writable root %s: %v", fs.fuseFS.writableRoot, code))
	}
	return fs, nil
}