Beispiel #1
0
func connectNBD(srv *torus.Server, f *block.BlockFile, target string, closer chan bool) error {
	defer f.Close()
	size := f.Size()

	gmd := srv.MDS.GlobalMetadata()

	handle := nbd.Create(f, int64(size), int64(gmd.BlockSize))

	if target == "" {
		t, err := nbd.FindDevice()
		if err != nil {
			return err
		}
		target = t
	}

	_, err := handle.OpenDevice(target)
	if err != nil {
		return err
	}

	go func(n *nbd.NBD) {
		<-closer
		n.Disconnect()
	}(handle)

	err = handle.Serve()
	if err != nil {
		return fmt.Errorf("error from nbd server: %s", err)
	}
	return nil
}
func connectNBD(srv *torus.Server, f *block.BlockFile, target string, closer chan bool) error {
	defer f.Close()
	size := f.Size()

	gmd, err := srv.MDS.GlobalMetadata()
	if err != nil {
		return err
	}

	handle := nbd.Create(f, int64(size), int64(gmd.BlockSize))

	if target == "" {
		target, err = nbd.FindDevice()
		if err != nil {
			fmt.Println(err)
			return err
		}
	}

	dev, err := handle.OpenDevice(target)
	if err != nil {
		fmt.Println(err)
		return err
	}
	fmt.Println("Connected to", dev)

	go func(n *nbd.NBD) {
		<-closer
		n.Disconnect()
	}(handle)

	err = handle.Serve()
	if err != nil {
		fmt.Fprintf(os.Stderr, "error from nbd server: %s\n", err)
		os.Exit(1)
	}
	return handle.Close()
}