Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Storage policy handling
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lucas <[email protected]>
  • Loading branch information
Xavier Lucas committed Sep 22, 2016
1 parent 54dd4aa commit 99cdab3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/mount.svfs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions svfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion svfs/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

const (
segmentContainerSuffix = "_segments"
storagePolicyHeader = "X-Storage-Policy"
)

var (
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 99cdab3

Please sign in to comment.