Esempio n. 1
0
func (d *kvfsDriver) create(name string, opts map[string]string) (*vol, error) {
	store := d.store
	if s, exists := opts["store"]; exists {
		store = s
	}

	addrs := d.addrs
	if a, exists := opts["addrs"]; exists {
		addrs = getAddrs(a)
	}
	kvOpts := fs.Options{
		Store: store,
		Addrs: addrs,
		Root:  opts["root"],
	}
	kv, err := fs.NewKVFS(kvOpts)
	if err != nil {
		return nil, err
	}

	mp := getMountpoint(d.home, name)
	if err := os.MkdirAll(mp, 0700); err != nil {
		return nil, err
	}

	srv, err := kv.NewServer(mp)
	if err != nil {
		return nil, err
	}
	go srv.Serve()

	return &vol{kv, getMountpoint(d.home, name), name, srv}, nil
}
Esempio n. 2
0
func main() {
	flag.Var(&flAddrs, "addr", "List of address to KV store")
	flag.Parse()

	if len(flAddrs) == 0 {
		logrus.Fatal("need at least one addr to connect to kv store")
	}

	if *flMountpoint == "" {
		logrus.Fatal("invalid mount point, must set the `-to` flag")
	}

	if _, err := os.Stat(*flMountpoint); err != nil {
		logrus.Fatalf("error with specified mountpoint %s: %v", *flMountpoint, err)
	}

	if *flStore == "" {
		logrus.Fatal("must specify a valid KV store")
	}

	if *flDebug {
		logrus.SetLevel(logrus.DebugLevel)
	}

	fs, err := fs.NewKVFS(fs.Options{*flStore, flAddrs.GetAll(), *flRoot, store.Config{}})
	if err != nil {
		logrus.Fatal(err)
	}

	srv, err := fs.NewServer(*flMountpoint)
	if err != nil {
		logrus.Fatal(err)
	}

	signal.Trap(func() {
		srv.Unmount()
	})
	srv.Serve()
}