You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.7 KiB
133 lines
3.7 KiB
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
|
"net/rpc"
|
||
|
|
||
|
router "github.com/gorilla/mux"
|
||
|
)
|
||
|
|
||
|
// Storage server implements rpc primitives to facilitate exporting a
|
||
|
// disk over a network.
|
||
|
type storageServer struct {
|
||
|
storage StorageAPI
|
||
|
}
|
||
|
|
||
|
/// Volume operations handlers
|
||
|
|
||
|
// MakeVolHandler - make vol handler is rpc wrapper for MakeVol operation.
|
||
|
func (s *storageServer) MakeVolHandler(arg *string, reply *GenericReply) error {
|
||
9 years ago
|
err := s.storage.MakeVol(*arg)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
9 years ago
|
}
|
||
|
|
||
|
// ListVolsHandler - list vols handler is rpc wrapper for ListVols operation.
|
||
|
func (s *storageServer) ListVolsHandler(arg *string, reply *ListVolsReply) error {
|
||
|
vols, err := s.storage.ListVols()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
reply.Vols = vols
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// StatVolHandler - stat vol handler is a rpc wrapper for StatVol operation.
|
||
|
func (s *storageServer) StatVolHandler(arg *string, reply *VolInfo) error {
|
||
|
volInfo, err := s.storage.StatVol(*arg)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
*reply = volInfo
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// DeleteVolHandler - delete vol handler is a rpc wrapper for
|
||
|
// DeleteVol operation.
|
||
|
func (s *storageServer) DeleteVolHandler(arg *string, reply *GenericReply) error {
|
||
9 years ago
|
err := s.storage.DeleteVol(*arg)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
9 years ago
|
}
|
||
|
|
||
|
/// File operations
|
||
|
|
||
9 years ago
|
// StatFileHandler - stat file handler is rpc wrapper to stat file.
|
||
|
func (s *storageServer) StatFileHandler(arg *StatFileArgs, reply *FileInfo) error {
|
||
|
fileInfo, err := s.storage.StatFile(arg.Vol, arg.Path)
|
||
9 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
9 years ago
|
*reply = fileInfo
|
||
9 years ago
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// ListDirHandler - list directory handler is rpc wrapper to list dir.
|
||
|
func (s *storageServer) ListDirHandler(arg *ListDirArgs, reply *[]string) error {
|
||
|
entries, err := s.storage.ListDir(arg.Vol, arg.Path)
|
||
9 years ago
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
9 years ago
|
*reply = entries
|
||
9 years ago
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// ReadAllHandler - read all handler is rpc wrapper to read all storage API.
|
||
|
func (s *storageServer) ReadAllHandler(arg *ReadFileArgs, reply *[]byte) error {
|
||
|
buf, err := s.storage.ReadAll(arg.Vol, arg.Path)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
reply = &buf
|
||
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
// ReadFileHandler - read file handler is rpc wrapper to read file.
|
||
|
func (s *storageServer) ReadFileHandler(arg *ReadFileArgs, reply *int64) error {
|
||
|
n, err := s.storage.ReadFile(arg.Vol, arg.Path, arg.Offset, arg.Buffer)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
reply = &n
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// AppendFileHandler - append file handler is rpc wrapper to append file.
|
||
9 years ago
|
func (s *storageServer) AppendFileHandler(arg *AppendFileArgs, reply *GenericReply) error {
|
||
|
return s.storage.AppendFile(arg.Vol, arg.Path, arg.Buffer)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// DeleteFileHandler - delete file handler is rpc wrapper to delete file.
|
||
|
func (s *storageServer) DeleteFileHandler(arg *DeleteFileArgs, reply *GenericReply) error {
|
||
9 years ago
|
return s.storage.DeleteFile(arg.Vol, arg.Path)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// RenameFileHandler - rename file handler is rpc wrapper to rename file.
|
||
|
func (s *storageServer) RenameFileHandler(arg *RenameFileArgs, reply *GenericReply) error {
|
||
9 years ago
|
return s.storage.RenameFile(arg.SrcVol, arg.SrcPath, arg.DstVol, arg.DstPath)
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
// Initialize new storage rpc.
|
||
9 years ago
|
func newRPCServer(exportPath string) (*storageServer, error) {
|
||
|
// Initialize posix storage API.
|
||
|
storage, err := newPosix(exportPath)
|
||
9 years ago
|
if err != nil && err != errDiskNotFound {
|
||
9 years ago
|
return nil, err
|
||
9 years ago
|
}
|
||
9 years ago
|
return &storageServer{
|
||
|
storage: storage,
|
||
|
}, nil
|
||
9 years ago
|
}
|
||
|
|
||
|
// registerStorageRPCRouter - register storage rpc router.
|
||
|
func registerStorageRPCRouter(mux *router.Router, stServer *storageServer) {
|
||
9 years ago
|
storageRPCServer := rpc.NewServer()
|
||
9 years ago
|
storageRPCServer.RegisterName("Storage", stServer)
|
||
|
storageRouter := mux.NewRoute().PathPrefix(reservedBucket).Subrouter()
|
||
9 years ago
|
// Add minio storage routes.
|
||
9 years ago
|
storageRouter.Path("/storage").Handler(storageRPCServer)
|
||
9 years ago
|
}
|