2016-07-31 23:11:14 +02:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 23:50:50 +02:00
|
|
|
package cmd
|
2016-04-08 19:37:38 +02:00
|
|
|
|
|
|
|
import (
|
2016-08-12 04:32:04 +02:00
|
|
|
"io"
|
2016-07-31 23:11:14 +02:00
|
|
|
"path"
|
2016-04-08 19:37:38 +02:00
|
|
|
|
2018-04-22 04:23:54 +02:00
|
|
|
"github.com/gorilla/mux"
|
2018-04-06 00:04:40 +02:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-06-06 10:51:56 +02:00
|
|
|
xrpc "github.com/minio/minio/cmd/rpc"
|
2016-04-08 19:37:38 +02:00
|
|
|
)
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
const storageServiceName = "Storage"
|
|
|
|
const storageServiceSubPath = "/storage"
|
|
|
|
|
|
|
|
var storageServicePath = path.Join(minioReservedBucketPath, storageServiceSubPath)
|
|
|
|
|
|
|
|
// storageRPCReceiver - Storage RPC receiver for storage RPC server
|
|
|
|
type storageRPCReceiver struct {
|
|
|
|
local *posix
|
|
|
|
}
|
|
|
|
|
|
|
|
// VolArgs - generic volume args.
|
|
|
|
type VolArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2016-08-26 02:16:34 +02:00
|
|
|
/// Storage operations handlers.
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// Connect - authenticates remote connection.
|
|
|
|
func (receiver *storageRPCReceiver) Connect(args *AuthArgs, reply *VoidReply) (err error) {
|
|
|
|
return args.Authenticate()
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// DiskInfo - disk info handler is rpc wrapper for DiskInfo operation.
|
|
|
|
func (receiver *storageRPCReceiver) DiskInfo(args *AuthArgs, reply *DiskInfo) (err error) {
|
|
|
|
*reply, err = receiver.local.DiskInfo()
|
2016-08-26 02:16:34 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Volume operations handlers.
|
2016-04-08 19:37:38 +02:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// MakeVol - make vol handler is rpc wrapper for MakeVol operation.
|
|
|
|
func (receiver *storageRPCReceiver) MakeVol(args *VolArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.MakeVol(args.Vol)
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// ListVols - list vols handler is rpc wrapper for ListVols operation.
|
|
|
|
func (receiver *storageRPCReceiver) ListVols(args *AuthArgs, reply *[]VolInfo) (err error) {
|
|
|
|
*reply, err = receiver.local.ListVols()
|
|
|
|
return err
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// StatVol - stat vol handler is a rpc wrapper for StatVol operation.
|
|
|
|
func (receiver *storageRPCReceiver) StatVol(args *VolArgs, reply *VolInfo) (err error) {
|
|
|
|
*reply, err = receiver.local.StatVol(args.Vol)
|
|
|
|
return err
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// DeleteVol - delete vol handler is a rpc wrapper for
|
2016-04-08 19:37:38 +02:00
|
|
|
// DeleteVol operation.
|
2018-06-06 10:51:56 +02:00
|
|
|
func (receiver *storageRPCReceiver) DeleteVol(args *VolArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.DeleteVol(args.Vol)
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// File operations
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// StatFileArgs represents stat file RPC arguments.
|
|
|
|
type StatFileArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// StatFile - stat file handler is rpc wrapper to stat file.
|
|
|
|
func (receiver *storageRPCReceiver) StatFile(args *StatFileArgs, reply *FileInfo) (err error) {
|
|
|
|
*reply, err = receiver.local.StatFile(args.Vol, args.Path)
|
|
|
|
return err
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// ListDirArgs represents list contents RPC arguments.
|
|
|
|
type ListDirArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
Count int
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// ListDir - list directory handler is rpc wrapper to list dir.
|
|
|
|
func (receiver *storageRPCReceiver) ListDir(args *ListDirArgs, reply *[]string) (err error) {
|
|
|
|
*reply, err = receiver.local.ListDir(args.Vol, args.Path, args.Count)
|
|
|
|
return err
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// ReadAllArgs represents read all RPC arguments.
|
|
|
|
type ReadAllArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// ReadAll - read all handler is rpc wrapper to read all storage API.
|
|
|
|
func (receiver *storageRPCReceiver) ReadAll(args *ReadAllArgs, reply *[]byte) (err error) {
|
|
|
|
*reply, err = receiver.local.ReadAll(args.Vol, args.Path)
|
|
|
|
return err
|
2016-06-25 23:51:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// ReadFileArgs represents read file RPC arguments.
|
|
|
|
type ReadFileArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
Offset int64
|
|
|
|
Buffer []byte
|
|
|
|
Algo BitrotAlgorithm
|
|
|
|
ExpectedHash []byte
|
|
|
|
Verified bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadFile - read file handler is rpc wrapper to read file.
|
|
|
|
func (receiver *storageRPCReceiver) ReadFile(args *ReadFileArgs, reply *[]byte) error {
|
2017-09-25 20:32:56 +02:00
|
|
|
var verifier *BitrotVerifier
|
|
|
|
if !args.Verified {
|
|
|
|
verifier = NewBitrotVerifier(args.Algo, args.ExpectedHash)
|
2016-08-12 04:32:04 +02:00
|
|
|
}
|
2016-05-29 00:13:15 +02:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
n, err := receiver.local.ReadFile(args.Vol, args.Path, args.Offset, args.Buffer, verifier)
|
|
|
|
// Ignore io.ErrEnexpectedEOF for short reads i.e. less content available than requested.
|
2017-05-16 23:21:52 +02:00
|
|
|
if err == io.ErrUnexpectedEOF {
|
|
|
|
err = nil
|
|
|
|
}
|
2018-06-06 10:51:56 +02:00
|
|
|
|
2017-05-16 23:21:52 +02:00
|
|
|
*reply = args.Buffer[0:n]
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// PrepareFileArgs represents append file RPC arguments.
|
|
|
|
type PrepareFileArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
Size int64
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// PrepareFile - prepare file handler is rpc wrapper to prepare file.
|
|
|
|
func (receiver *storageRPCReceiver) PrepareFile(args *PrepareFileArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.PrepareFile(args.Vol, args.Path, args.Size)
|
2016-10-29 21:44:44 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// AppendFileArgs represents append file RPC arguments.
|
|
|
|
type AppendFileArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
Buffer []byte
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// AppendFile - append file handler is rpc wrapper to append file.
|
|
|
|
func (receiver *storageRPCReceiver) AppendFile(args *AppendFileArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.AppendFile(args.Vol, args.Path, args.Buffer)
|
2016-05-29 00:13:15 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// DeleteFileArgs represents delete file RPC arguments.
|
|
|
|
type DeleteFileArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
Vol string
|
|
|
|
Path string
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// DeleteFile - delete file handler is rpc wrapper to delete file.
|
|
|
|
func (receiver *storageRPCReceiver) DeleteFile(args *DeleteFileArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.DeleteFile(args.Vol, args.Path)
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// RenameFileArgs represents rename file RPC arguments.
|
|
|
|
type RenameFileArgs struct {
|
|
|
|
AuthArgs
|
|
|
|
SrcVol string
|
|
|
|
SrcPath string
|
|
|
|
DstVol string
|
|
|
|
DstPath string
|
|
|
|
}
|
2016-12-23 16:12:19 +01:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// RenameFile - rename file handler is rpc wrapper to rename file.
|
|
|
|
func (receiver *storageRPCReceiver) RenameFile(args *RenameFileArgs, reply *VoidReply) error {
|
|
|
|
return receiver.local.RenameFile(args.SrcVol, args.SrcPath, args.DstVol, args.DstPath)
|
2016-05-02 12:12:18 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
// NewStorageRPCServer - returns new storage RPC server.
|
|
|
|
func NewStorageRPCServer(endpointPath string) (*xrpc.Server, error) {
|
|
|
|
storage, err := newPosix(endpointPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|
2017-04-12 00:44:27 +02:00
|
|
|
|
2018-06-06 10:51:56 +02:00
|
|
|
rpcServer := xrpc.NewServer()
|
|
|
|
if err = rpcServer.RegisterName(storageServiceName, &storageRPCReceiver{storage}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return rpcServer, nil
|
2016-04-20 05:05:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// registerStorageRPCRouter - register storage rpc router.
|
2018-06-06 10:51:56 +02:00
|
|
|
func registerStorageRPCRouters(router *mux.Router, endpoints EndpointList) {
|
|
|
|
for _, endpoint := range endpoints {
|
|
|
|
if endpoint.IsLocal {
|
|
|
|
rpcServer, err := NewStorageRPCServer(endpoint.Path)
|
2018-06-07 03:10:51 +02:00
|
|
|
if err != nil {
|
|
|
|
logger.Fatal(uiErrUnableToWriteInBackend(err), "Unable to configure one of server's RPC services")
|
|
|
|
}
|
2018-06-06 10:51:56 +02:00
|
|
|
subrouter := router.PathPrefix(minioReservedBucketPath).Subrouter()
|
2018-08-07 11:51:30 +02:00
|
|
|
subrouter.Path(path.Join(storageServiceSubPath, endpoint.Path)).HandlerFunc(httpTraceHdrs(rpcServer.ServeHTTP))
|
2016-10-13 08:13:24 +02:00
|
|
|
}
|
2016-07-31 23:11:14 +02:00
|
|
|
}
|
2016-04-08 19:37:38 +02:00
|
|
|
}
|