Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #181 from mdlayher/aoe-major-minor
Browse files Browse the repository at this point in the history
block/aoe, cmd/torusblk: allow AoE server major and minor address con…
  • Loading branch information
barakmich committed Jun 1, 2016
2 parents fbcfbde + cfad297 commit 043ff77
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
31 changes: 28 additions & 3 deletions block/aoe/aoe.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,32 @@ type Server struct {
minor uint8
}

func NewServer(b *block.BlockVolume) (*Server, error) {
// ServerOptions specifies options for a Server.
type ServerOptions struct {
// Major and Minor specify the major and minor address of an AoE server.
// Typically, all AoE devices on a single server will share the same
// major address, but have different minor addresses.
//
// It is important to note that all AoE servers on the same layer 2
// network must have different major and minor addresses.
Major uint16
Minor uint8
}

// DefaultServerOptions is the default ServerOptions configuration used
// by NewServer when none is specified.
var DefaultServerOptions = &ServerOptions{
Major: 1,
Minor: 1,
}

// NewServer creates a new Server which utilizes the specified block volume.
// If options is nil, DefaultServerOptions will be used.
func NewServer(b *block.BlockVolume, options *ServerOptions) (*Server, error) {
if options == nil {
options = DefaultServerOptions
}

f, err := b.OpenBlockFile()
if err != nil {
return nil, err
Expand All @@ -39,8 +64,8 @@ func NewServer(b *block.BlockVolume) (*Server, error) {
as := &Server{
dfs: b,
dev: fd,
major: 1,
minor: 1,
major: options.Major,
minor: options.Minor,
}

return as, nil
Expand Down
38 changes: 34 additions & 4 deletions cmd/torusblk/aoe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"
"os/signal"
"strconv"
"strings"

"github.com/spf13/cobra"

Expand All @@ -13,13 +15,26 @@ import (
)

var aoeCommand = &cobra.Command{
Use: "aoe VOLUME INTERFACE",
Use: "aoe VOLUME INTERFACE MAJOR MINOR",
Short: "serve a volume over AoE [EXPERIMENTAL]",
Run: aoeAction,
Long: strings.TrimSpace(`
Serve a volume over AoE using the specified network interface and AoE
major and minor addresses.
It is important to note that all AoE servers on the same layer 2 network
must have different major and minor addresses.
An example of serving two volumes using AoE on the same server over the
eth0 network interface:
torusblk aoe vol01 eth0 1 1
torusblk aoe vol02 eth0 1 2
`),
Run: aoeAction,
}

func aoeAction(cmd *cobra.Command, args []string) {
if len(args) != 2 {
if len(args) != 4 {
cmd.Usage()
os.Exit(1)
}
Expand All @@ -28,6 +43,18 @@ func aoeAction(cmd *cobra.Command, args []string) {

vol := args[0]
ifname := args[1]
maj := args[2]
min := args[3]

major, err := strconv.ParseUint(maj, 10, 16)
if err != nil {
die("Failed to parse major address %q: %v\n", maj, err)
}

minor, err := strconv.ParseUint(min, 10, 8)
if err != nil {
die("Failed to parse minor address %q: %v\n", min, err)
}

blockvol, err := block.OpenBlockVolume(srv, vol)
if err != nil {
Expand All @@ -41,7 +68,10 @@ func aoeAction(cmd *cobra.Command, args []string) {
os.Exit(1)
}

as, err := aoe.NewServer(blockvol)
as, err := aoe.NewServer(blockvol, &aoe.ServerOptions{
Major: uint16(major),
Minor: uint8(minor),
})
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to crate AoE server: %v\n", err)
os.Exit(1)
Expand Down

0 comments on commit 043ff77

Please sign in to comment.