Esempio n. 1
0
func createVol(t *testing.T, server *torus.Server, volname string, size uint64) *block.BlockFile {
	err := block.CreateBlockVolume(server.MDS, volname, size)
	if err != nil {
		t.Fatalf("couldn't create block volume %s: %v", volname, err)
	}
	return openVol(t, server, volname)
}
Esempio n. 2
0
func BenchmarkLoadThree(b *testing.B) {
	b.StopTimer()

	servers, mds := ringN(b, 3)
	client := newServer(b, mds)
	err := distributor.OpenReplication(client)
	if err != nil {
		b.Fatal(err)
	}
	defer client.Close()
	size := BlockSize * 100
	data := makeTestData(size)

	b.StartTimer()

	for i := 0; i < b.N; i++ {
		input := bytes.NewReader(data)
		volname := fmt.Sprintf("testvol-%d", i)

		err = block.CreateBlockVolume(client.MDS, volname, uint64(size))
		if err != nil {
			b.Fatalf("couldn't create block volume %s: %v", volname, err)
		}
		blockvol, err := block.OpenBlockVolume(client, volname)
		if err != nil {
			b.Fatalf("couldn't open block volume %s: %v", volname, err)
		}
		f, err := blockvol.OpenBlockFile()
		if err != nil {
			b.Fatalf("couldn't open blockfile %s: %v", volname, err)
		}
		copied, err := io.Copy(f, input)
		if err != nil {
			b.Fatalf("couldn't copy: %v", err)
		}
		err = f.Sync()
		if err != nil {
			b.Fatalf("couldn't sync: %v", err)
		}
		err = f.Close()
		if err != nil {
			b.Fatalf("couldn't close: %v", err)
		}

		b.Logf("copied %d bytes", copied)
	}

	b.SetBytes(int64(size))

	b.StopTimer()
	closeAll(b, servers...)
	b.StartTimer()
}
func volumeCreateBlockAction(cmd *cobra.Command, args []string) {
	mds := mustConnectToMDS()
	if len(args) != 2 {
		cmd.Usage()
		os.Exit(1)
	}
	size, err := humanize.ParseBytes(args[1])
	if err != nil {
		die("error parsing size %s: %v", args[1], err)
	}
	err = block.CreateBlockVolume(mds, args[0], size)
	if err != nil {
		die("error creating volume %s: %v", args[0], err)
	}
}
// testAoEServer sets up a Torus AoE server and returns:
//  - an io.Reader which contains the server's response to a request
//  - an io.Writer which can be used to issue a request to the server
//  - a closure which can be used to run the server for a single
//    request/response cycle
//  - a closure which can be used to tear down all server resources
func testAoEServer(t *testing.T) (response io.Reader, request io.Writer, run func() error, done func()) {
	ts := torus.NewMemoryServer()

	mds, err := temp.NewTemp(ts.Cfg)
	if err != nil {
		t.Fatalf("failed to configure metadata service: %v", err)
	}
	ts.MDS = mds

	const volName = "test"
	if err := block.CreateBlockVolume(mds, volName, 1024); err != nil {
		t.Fatalf("failed to create block volume: %v", err)
	}

	vol, err := block.OpenBlockVolume(ts, volName)
	if err != nil {
		t.Fatalf("error opening block volume: %v", err)
	}

	as, err := NewServer(vol, nil)
	if err != nil {
		t.Fatalf("error opening AoE server: %v", err)
	}

	serverWrite := bytes.NewBuffer(nil)
	serverRead := bytes.NewBuffer(nil)

	bp := &bufPacketConn{
		rb: serverWrite,
		wb: serverRead,
	}

	iface := &Interface{
		Interface: &net.Interface{
			Name: "lo",
			MTU:  testMTU,
		},
		PacketConn: bp,
	}

	run = func() error {
		if err := as.Serve(iface); err != nil {
			return fmt.Errorf("failed to serve AoE: %v", err)
		}

		bp.mu.Lock()
		defer bp.mu.Unlock()

		if !bp.gotBroadcast {
			return errors.New("broadcast advertise was never received")
		}

		return nil
	}

	done = func() {
		_ = as.Close()
		_ = iface.PacketConn.Close()
		_ = ts.Close()
	}

	return serverRead, serverWrite, run, done
}
Esempio n. 5
0
func blockLoadAction(cmd *cobra.Command, args []string) error {
	if len(args) != 2 && len(args) != 3 {
		return torus.ErrUsage
	}
	input, err := getReaderFromArg(args[0])
	if err != nil {
		return fmt.Errorf("couldn't open input: %v", err)
	}
	srv := createServer()
	defer srv.Close()
	fi, err := input.Stat()
	if err != nil {
		return fmt.Errorf("couldn't stat input file: %v", err)
	}

	size := uint64(fi.Size())
	if len(args) == 3 {
		expSize, err := humanize.ParseBytes(args[2])
		if err != nil {
			return fmt.Errorf("error parsing size %s: %v", args[2], err)
		}

		if expSize < size {
			return fmt.Errorf("size must be larger than input file")
		}

		size = expSize
	}

	err = block.CreateBlockVolume(srv.MDS, args[1], size)
	if err != nil {
		return fmt.Errorf("couldn't create block volume %s: %v", args[1], err)
	}
	blockvol, err := block.OpenBlockVolume(srv, args[1])
	if err != nil {
		return fmt.Errorf("couldn't open block volume %s: %v", args[1], err)
	}
	f, err := blockvol.OpenBlockFile()
	if err != nil {
		return fmt.Errorf("couldn't open blockfile %s: %v", args[1], err)
	}
	defer f.Close()

	if progress {
		pb := progressutil.NewCopyProgressPrinter()
		pb.AddCopy(input, path.Base(args[0]), fi.Size(), f)
		err := pb.PrintAndWait(os.Stderr, 500*time.Millisecond, nil)
		if err != nil {
			return fmt.Errorf("couldn't copy: %v", err)
		}
	} else {
		_, err := io.Copy(f, input)
		if err != nil {
			return fmt.Errorf("couldn't copy: %v", err)
		}
	}

	err = f.Sync()
	if err != nil {
		return fmt.Errorf("couldn't sync: %v", err)
	}
	fmt.Printf("copied %d bytes\n", fi.Size())
	return nil
}