Skip to content

Commit

Permalink
Merge pull request #101 from Ruakij/master
Browse files Browse the repository at this point in the history
Whitelist for volContext
  • Loading branch information
chrislusf authored Jan 16, 2023
2 parents 318c42a + 3be6e2f commit f4d651d
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions pkg/driver/mounter_seaweedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ func (seaweedFs *seaweedFsMounter) Mount(target string) (Unmounter, error) {
args = append(args, fmt.Sprintf("-collectionQuotaMB=%d", capacityMB))
}

// Initial values for override-able args
// Values for override-able args
// Whitelist for merging with volContext
argsMap := map[string]string {
"collection": seaweedFs.collection,
"filer": strings.Join(filers, ","),
Expand All @@ -83,6 +84,13 @@ func (seaweedFs *seaweedFsMounter) Mount(target string) (Unmounter, error) {
"concurrentWriters": fmt.Sprint(seaweedFs.driver.ConcurrentWriters),
"map.uid": seaweedFs.driver.UidMap,
"map.gid": seaweedFs.driver.GidMap,
"disk": "",
"dataCenter": "",
"replication": "",
"ttl": "",
"chunkSizeLimitMB": "",
"volumeServerAccess": "",
"readRetryTime": "",
}

// volContext-parameter -> mount-arg
Expand All @@ -93,19 +101,28 @@ func (seaweedFs *seaweedFsMounter) Mount(target string) (Unmounter, error) {
// volumeContext has "diskType", but mount-option is "disk", converting for backwards compatability
"diskType": "disk",
}

// Explicitly ignored volContext args e.g. handled somewhere else
ignoreArgs := []string{
"volumeCapacity",
}

// Merge volContext into argsMap with key-mapping
for arg, value := range seaweedFs.volContext {
if(arg == "volumeCapacity"){ // Ignore volumeCapacity, not the nicest solution like this :/
continue
}
if(in_arr(ignoreArgs, arg)){continue}

// Check if key-mapping exists
newArg, ok := parameterArgMap[arg]
if(ok){
arg = newArg
}

// Check if arg can be applied
if _, ok := argsMap[arg]; !ok {
glog.Warningf("VolumeContext '%s' ignored", arg)
continue
}

// Write to args-map
argsMap[arg] = value
}
Expand Down Expand Up @@ -153,3 +170,12 @@ func parseVolumeCapacity(volumeCapacity string) int64 {
capacityMB := capacity / 1024 / 1024
return capacityMB
}

func in_arr(arr []string, val string) bool {
for _, v := range arr {
if(val == v) {
return true
}
}
return false
}

0 comments on commit f4d651d

Please sign in to comment.