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() }
func ConnectAndServe(f *block.BlockFile, name string, closer chan bool) error { wwn := tcmu.NaaWWN{ // TODO(barakmich): CoreOS OUI here OUI: "000000", VendorID: tcmu.GenerateSerial(name), } h := &tcmu.SCSIHandler{ HBA: 30, LUN: 0, WWN: wwn, VolumeName: name, // 1GiB, 1K DataSizes: tcmu.DataSizes{ VolumeSize: int64(f.Size()), BlockSize: defaultBlockSize, }, DevReady: tcmu.MultiThreadedDevReady( &torusHandler{ file: f, name: name, inq: &tcmu.InquiryInfo{ VendorID: "CoreOS", ProductID: "TorusBlk", ProductRev: "0001", }, }, 1), } d, err := tcmu.OpenTCMUDevice(devPath, h) if err != nil { return err } defer d.Close() fmt.Printf("Attached to %s/%s. Server loop begins ... \n", devPath, name) <-closer return nil }