server: Fetch StorageInfo() from underlying disks transparently. (#2549)

Fixes #2511
This commit is contained in:
Harshavardhana 2016-08-25 17:16:34 -07:00
parent fa6e9540a8
commit 339425fd52
7 changed files with 50 additions and 18 deletions

View File

@ -4,9 +4,9 @@ language: go
os: os:
- linux - linux
- osx #- osx
osx_image: xcode7.2 #osx_image: xcode7.2
env: env:
- ARCH=x86_64 - ARCH=x86_64

View File

@ -26,7 +26,6 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/minio/minio/pkg/disk"
"github.com/minio/minio/pkg/mimedb" "github.com/minio/minio/pkg/mimedb"
) )
@ -146,8 +145,8 @@ func (fs fsObjects) Shutdown() error {
// StorageInfo - returns underlying storage statistics. // StorageInfo - returns underlying storage statistics.
func (fs fsObjects) StorageInfo() StorageInfo { func (fs fsObjects) StorageInfo() StorageInfo {
info, err := disk.GetInfo(fs.physicalDisk) info, err := fs.storage.DiskInfo()
fatalIf(err, "Unable to get disk info "+fs.physicalDisk) errorIf(err, "Unable to get disk info %#v", fs.storage)
return StorageInfo{ return StorageInfo{
Total: info.Total, Total: info.Total,
Free: info.Free, Free: info.Free,

View File

@ -160,6 +160,12 @@ func checkDiskFree(diskPath string, minFreeDisk int64) (err error) {
return nil return nil
} }
// DiskInfo provides current information about disk space usage,
// total free inodes and underlying filesystem.
func (s *posix) DiskInfo() (info disk.Info, err error) {
return getDiskInfo(s.diskPath)
}
// getVolDir - will convert incoming volume names to // getVolDir - will convert incoming volume names to
// corresponding valid volume names on the backend in a platform // corresponding valid volume names on the backend in a platform
// compatible way for all operating systems. If volume is not found // compatible way for all operating systems. If volume is not found

View File

@ -16,8 +16,13 @@
package cmd package cmd
import "github.com/minio/minio/pkg/disk"
// StorageAPI interface. // StorageAPI interface.
type StorageAPI interface { type StorageAPI interface {
// Storage operations.
DiskInfo() (info disk.Info, err error)
// Volume operations. // Volume operations.
MakeVol(volume string) (err error) MakeVol(volume string) (err error)
ListVols() (vols []VolInfo, err error) ListVols() (vols []VolInfo, err error)

View File

@ -21,6 +21,8 @@ import (
"path" "path"
"strconv" "strconv"
"strings" "strings"
"github.com/minio/minio/pkg/disk"
) )
type networkStorage struct { type networkStorage struct {
@ -110,7 +112,16 @@ func newRPCClient(networkPath string) (StorageAPI, error) {
return ndisk, nil return ndisk, nil
} }
// MakeVol - make a volume. // DiskInfo - fetch disk information for a remote disk.
func (n networkStorage) DiskInfo() (info disk.Info, err error) {
args := GenericArgs{}
if err = n.rpcClient.Call("Storage.DiskInfoHandler", &args, &info); err != nil {
return disk.Info{}, err
}
return info, nil
}
// MakeVol - create a volume on a remote disk.
func (n networkStorage) MakeVol(volume string) error { func (n networkStorage) MakeVol(volume string) error {
reply := GenericReply{} reply := GenericReply{}
args := GenericVolArgs{Vol: volume} args := GenericVolArgs{Vol: volume}
@ -120,7 +131,7 @@ func (n networkStorage) MakeVol(volume string) error {
return nil return nil
} }
// ListVols - List all volumes. // ListVols - List all volumes on a remote disk.
func (n networkStorage) ListVols() (vols []VolInfo, err error) { func (n networkStorage) ListVols() (vols []VolInfo, err error) {
ListVols := ListVolsReply{} ListVols := ListVolsReply{}
err = n.rpcClient.Call("Storage.ListVolsHandler", &GenericArgs{}, &ListVols) err = n.rpcClient.Call("Storage.ListVolsHandler", &GenericArgs{}, &ListVols)

View File

@ -24,6 +24,7 @@ import (
"strings" "strings"
router "github.com/gorilla/mux" router "github.com/gorilla/mux"
"github.com/minio/minio/pkg/disk"
) )
// Storage server implements rpc primitives to facilitate exporting a // Storage server implements rpc primitives to facilitate exporting a
@ -53,7 +54,19 @@ func (s *storageServer) LoginHandler(args *RPCLoginArgs, reply *RPCLoginReply) e
return nil return nil
} }
/// Volume operations handlers /// Storage operations handlers.
// DiskInfoHandler - disk info handler is rpc wrapper for DiskInfo operation.
func (s *storageServer) DiskInfoHandler(args *GenericArgs, reply *disk.Info) error {
if !isRPCTokenValid(args.Token) {
return errInvalidToken
}
info, err := s.storage.DiskInfo()
*reply = info
return err
}
/// Volume operations handlers.
// MakeVolHandler - make vol handler is rpc wrapper for MakeVol operation. // MakeVolHandler - make vol handler is rpc wrapper for MakeVol operation.
func (s *storageServer) MakeVolHandler(args *GenericVolArgs, reply *GenericReply) error { func (s *storageServer) MakeVolHandler(args *GenericVolArgs, reply *GenericReply) error {

View File

@ -50,7 +50,6 @@ const (
// xlObjects - Implements XL object layer. // xlObjects - Implements XL object layer.
type xlObjects struct { type xlObjects struct {
physicalDisks []string // Collection of regular disks.
storageDisks []StorageAPI // Collection of initialized backend disks. storageDisks []StorageAPI // Collection of initialized backend disks.
dataBlocks int // dataBlocks count caculated for erasure. dataBlocks int // dataBlocks count caculated for erasure.
parityBlocks int // parityBlocks count calculated for erasure. parityBlocks int // parityBlocks count calculated for erasure.
@ -186,7 +185,6 @@ func newXLObjects(disks, ignoredDisks []string) (ObjectLayer, error) {
// Initialize xl objects. // Initialize xl objects.
xl := xlObjects{ xl := xlObjects{
physicalDisks: disks,
storageDisks: newPosixDisks, storageDisks: newPosixDisks,
dataBlocks: dataBlocks, dataBlocks: dataBlocks,
parityBlocks: parityBlocks, parityBlocks: parityBlocks,
@ -222,10 +220,10 @@ func (d byDiskTotal) Less(i, j int) bool {
// StorageInfo - returns underlying storage statistics. // StorageInfo - returns underlying storage statistics.
func (xl xlObjects) StorageInfo() StorageInfo { func (xl xlObjects) StorageInfo() StorageInfo {
var disksInfo []disk.Info var disksInfo []disk.Info
for _, diskPath := range xl.physicalDisks { for _, storageDisk := range xl.storageDisks {
info, err := disk.GetInfo(diskPath) info, err := storageDisk.DiskInfo()
if err != nil { if err != nil {
errorIf(err, "Unable to fetch disk info for "+diskPath) errorIf(err, "Unable to fetch disk info for %#v", storageDisk)
continue continue
} }
disksInfo = append(disksInfo, info) disksInfo = append(disksInfo, info)