From 99cdab356ef34e88dbdb1e1891ee03c75763678a Mon Sep 17 00:00:00 2001 From: Xavier Lucas Date: Thu, 22 Sep 2016 15:44:47 +0200 Subject: [PATCH] Storage policy handling Signed-off-by: Xavier Lucas --- README.md | 2 ++ cmd/mount.go | 1 + scripts/mount.svfs | 1 + svfs/fs.go | 3 +++ svfs/root.go | 16 +++++++++++++++- 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec963dc..e9092fb 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ should also be set for this to work. #### Swift options * `container`: which container should be selected while mounting the filesystem. If not set, +* `storage_policy`: expected containers storage policy. This is used to ignore containers +not matching a particular storage policy name. If empty, this setting is ignored (default). all containers within the tenant will be available under the chosen mountpoint. * `segment_size`: large object segments size in MB. When an object has a content larger than this setting, it will be uploaded in multiple parts of the specified size. Default is 256 MB. diff --git a/cmd/mount.go b/cmd/mount.go index f7a34da..28ea28f 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -148,6 +148,7 @@ func setFlags() { flags.DurationVar(&svfs.SwiftConnection.ConnectTimeout, "os-connect-timeout", 15*time.Second, "Swift connection timeout") flags.DurationVar(&svfs.SwiftConnection.Timeout, "os-request-timeout", 5*time.Minute, "Swift operation timeout") flags.Uint64Var(&svfs.SegmentSize, "os-segment-size", 256, "Swift segment size in MiB") + flags.StringVar(&svfs.StoragePolicy, "os-storage-policy", "", "Only show containers using this storage policy") flags.StringVar(&swift.DefaultUserAgent, "user-agent", "svfs/"+svfs.Version, "Default User-Agent") //HubiC options diff --git a/scripts/mount.svfs b/scripts/mount.svfs index bf1f0b6..e02a79b 100755 --- a/scripts/mount.svfs +++ b/scripts/mount.svfs @@ -41,6 +41,7 @@ OPTIONS = { 'request_timeout' => '--os-request-timeout', 'ro' => '--read-only', 'segment_size' => '--os-segment-size', + 'storage_policy' => '--os-storage-policy', 'storage_url' => '--os-storage-url', 'tenant' => '--os-tenant-name', 'token' => '--os-auth-token', diff --git a/svfs/fs.go b/svfs/fs.go index a19d2ba..4dfbb20 100644 --- a/svfs/fs.go +++ b/svfs/fs.go @@ -26,6 +26,9 @@ var ( SwiftConnection = new(swift.Connection) // TargetContainer is an existing container ready to be served. TargetContainer string + // StoragePolicy represents a storage policy configured by the + // storage provider. + StoragePolicy string // ExtraAttr represents extra attributes fetching mode activation. ExtraAttr bool // HubicTimes represents the usage of hubiC synchronization clients diff --git a/svfs/root.go b/svfs/root.go index c1e689a..68fe43c 100644 --- a/svfs/root.go +++ b/svfs/root.go @@ -14,6 +14,7 @@ import ( const ( segmentContainerSuffix = "_segments" + storagePolicyHeader = "X-Storage-Policy" ) var ( @@ -38,7 +39,11 @@ func (r *Root) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, erro ) for _, name := range []string{req.Name, segmentContainer} { - err := SwiftConnection.ContainerCreate(name, nil) + headers := make(map[string]string) + if StoragePolicy != "" { + headers[storagePolicyHeader] = StoragePolicy + } + err := SwiftConnection.ContainerCreate(name, headers) if err != nil { return nil, err } @@ -108,6 +113,15 @@ func (r *Root) ReadDirAll(ctx context.Context) (direntries []fuse.Dirent, err er // Sort base and segment containers for _, segmentContainer := range cs { s := segmentContainer + if StoragePolicy != "" { + _, headers, err := SwiftConnection.Container(s.Name) + if err != nil { + return nil, err + } + if headers[storagePolicyHeader] != StoragePolicy { + continue + } + } if !segmentRegex.Match([]byte(s.Name)) { baseContainers[s.Name] = &s continue