api: Add diskInfo as part of StatVol and ListVols. (#1349)

It is the bucket and volumes which needs to have this
value rather than the DiskInfo API itself. Eventually
this can be extended to show disk usage per
Buckets/Volumes whenever we have that functionality.

For now since buckets/volumes are thinly provisioned
this is the right approach.
master
Harshavardhana 9 years ago committed by Anand Babu (AB) Periasamy
parent 1284ecc6f2
commit 4cf73caf02
  1. 2
      Browser.md
  2. 18
      fs.go
  3. 4
      object-api.go
  4. 2
      object-datatypes.go
  5. 19
      storage-datatypes.go
  6. 28
      web-handlers.go

@ -35,5 +35,3 @@ JSON RPC namespace is `Web`.
* PutObjectURL - generates a URL for upload access, requies a valid token. * PutObjectURL - generates a URL for upload access, requies a valid token.
(generated URL is valid for 1hr) (generated URL is valid for 1hr)
#### Server Operations.
* DiskInfo - get backend disk statistics.

18
fs.go

@ -226,6 +226,12 @@ func (s fsStorage) MakeVol(volume string) (err error) {
// ListVols - list volumes. // ListVols - list volumes.
func (s fsStorage) ListVols() (volsInfo []VolInfo, err error) { func (s fsStorage) ListVols() (volsInfo []VolInfo, err error) {
// Get disk info to be populated for VolInfo.
var diskInfo disk.Info
diskInfo, err = disk.GetInfo(s.diskPath)
if err != nil {
return nil, err
}
volsInfo, err = getAllUniqueVols(s.diskPath) volsInfo, err = getAllUniqueVols(s.diskPath)
if err != nil { if err != nil {
return nil, err return nil, err
@ -238,6 +244,9 @@ func (s fsStorage) ListVols() (volsInfo []VolInfo, err error) {
volInfo := VolInfo{ volInfo := VolInfo{
Name: volName, Name: volName,
Created: vol.Created, Created: vol.Created,
Total: diskInfo.Total,
Free: diskInfo.Free,
FSType: diskInfo.FSType,
} }
volsInfo[i] = volInfo volsInfo[i] = volInfo
} }
@ -260,12 +269,21 @@ func (s fsStorage) StatVol(volume string) (volInfo VolInfo, err error) {
} }
return VolInfo{}, err return VolInfo{}, err
} }
// Get disk info, to be returned back along with volume info.
var diskInfo disk.Info
diskInfo, err = disk.GetInfo(s.diskPath)
if err != nil {
return VolInfo{}, err
}
// As os.Stat() doesn't carry other than ModTime(), use ModTime() // As os.Stat() doesn't carry other than ModTime(), use ModTime()
// as CreatedTime. // as CreatedTime.
createdTime := st.ModTime() createdTime := st.ModTime()
return VolInfo{ return VolInfo{
Name: volume, Name: volume,
Created: createdTime, Created: createdTime,
Free: diskInfo.Free,
Total: diskInfo.Total,
FSType: diskInfo.FSType,
}, nil }, nil
} }

@ -72,6 +72,8 @@ func (o objectAPI) GetBucketInfo(bucket string) (BucketInfo, *probe.Error) {
return BucketInfo{ return BucketInfo{
Name: bucket, Name: bucket,
Created: vi.Created, Created: vi.Created,
Total: vi.Total,
Free: vi.Free,
}, nil }, nil
} }
@ -91,6 +93,8 @@ func (o objectAPI) ListBuckets() ([]BucketInfo, *probe.Error) {
bucketInfos = append(bucketInfos, BucketInfo{ bucketInfos = append(bucketInfos, BucketInfo{
Name: vol.Name, Name: vol.Name,
Created: vol.Created, Created: vol.Created,
Total: vol.Total,
Free: vol.Free,
}) })
} }
return bucketInfos, nil return bucketInfos, nil

@ -22,6 +22,8 @@ import "time"
type BucketInfo struct { type BucketInfo struct {
Name string Name string
Created time.Time Created time.Time
Total int64
Free int64
} }
// ObjectInfo - object info. // ObjectInfo - object info.

@ -1,3 +1,19 @@
/*
* 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.
*/
package main package main
import ( import (
@ -9,6 +25,9 @@ import (
type VolInfo struct { type VolInfo struct {
Name string Name string
Created time.Time Created time.Time
Total int64
Free int64
FSType string
} }
// FileInfo - file stat information. // FileInfo - file stat information.

@ -31,7 +31,6 @@ import (
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/rpc/v2/json2" "github.com/gorilla/rpc/v2/json2"
"github.com/minio/minio/pkg/disk"
"github.com/minio/miniobrowser" "github.com/minio/miniobrowser"
) )
@ -99,27 +98,6 @@ func (web *webAPIHandlers) ServerInfo(r *http.Request, args *WebGenericArgs, rep
return nil return nil
} }
// DiskInfoRep - disk info reply.
type DiskInfoRep struct {
DiskInfo disk.Info `json:"diskInfo"`
UIVersion string `json:"uiVersion"`
}
// DiskInfo - get disk statistics.
func (web *webAPIHandlers) DiskInfo(r *http.Request, args *WebGenericArgs, reply *DiskInfoRep) error {
// FIXME: bring in StatFS in StorageAPI interface and uncomment the below lines.
// if !isJWTReqAuthenticated(r) {
// return &json2.Error{Message: "Unauthorized request"}
// }
// info, e := disk.GetInfo(web.ObjectAPI.(*Filesystem).GetRootPath())
// if e != nil {
// return &json2.Error{Message: e.Error()}
// }
// reply.DiskInfo = info
// reply.UIVersion = miniobrowser.UIVersion
return nil
}
// MakeBucketArgs - make bucket args. // MakeBucketArgs - make bucket args.
type MakeBucketArgs struct { type MakeBucketArgs struct {
BucketName string `json:"bucketName"` BucketName string `json:"bucketName"`
@ -150,6 +128,10 @@ type WebBucketInfo struct {
Name string `json:"name"` Name string `json:"name"`
// Date the bucket was created. // Date the bucket was created.
CreationDate time.Time `json:"creationDate"` CreationDate time.Time `json:"creationDate"`
// Total storage space where the bucket resides.
Total int64 `json:"total"`
// Free storage space where the bucket resides.
Free int64 `json:"free"`
} }
// ListBuckets - list buckets api. // ListBuckets - list buckets api.
@ -167,6 +149,8 @@ func (web *webAPIHandlers) ListBuckets(r *http.Request, args *WebGenericArgs, re
reply.Buckets = append(reply.Buckets, WebBucketInfo{ reply.Buckets = append(reply.Buckets, WebBucketInfo{
Name: bucket.Name, Name: bucket.Name,
CreationDate: bucket.Created, CreationDate: bucket.Created,
Total: bucket.Total,
Free: bucket.Free,
}) })
} }
} }

Loading…
Cancel
Save