diff options
author | Fabricio Voznika <fvoznika@google.com> | 2018-05-10 12:46:27 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-10 12:47:15 -0700 |
commit | 31a4fefbe0a44377f75888284c9be0a3bec2a017 (patch) | |
tree | 662e5d0c0b30c9e92a835e040f52f0c5a274ff41 /pkg/sentry/fs/gofer | |
parent | 9d91c44d775cb204049a80405f3a2589f706795a (diff) |
Make cachePolicy int to avoid string comparison
PiperOrigin-RevId: 196157086
Change-Id: Ia7f7ffe1bf486b21ef8091e2e8ef9a9faf733dfc
Diffstat (limited to 'pkg/sentry/fs/gofer')
-rw-r--r-- | pkg/sentry/fs/gofer/fs.go | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/pkg/sentry/fs/gofer/fs.go b/pkg/sentry/fs/gofer/fs.go index 0a1a49bbd..a8a3ec19d 100644 --- a/pkg/sentry/fs/gofer/fs.go +++ b/pkg/sentry/fs/gofer/fs.go @@ -57,20 +57,26 @@ const ( ) // cachePolicy is a 9p cache policy. -type cachePolicy string +type cachePolicy int const ( - // Use virtual file system cache. - cacheAll cachePolicy = "fscache" - // TODO: fully support cache=none. - cacheNone cachePolicy = "none" + cacheNone cachePolicy = iota - // defaultCache is cacheAll. Note this diverges from the 9p Linux - // client whose default is "none". See TODO above. - defaultCache = cacheAll + // Use virtual file system cache. + cacheAll ) +func parseCachePolicy(policy string) (cachePolicy, error) { + switch policy { + case "fscache": + return cacheAll, nil + case "none": + return cacheNone, nil + } + return cacheNone, fmt.Errorf("unsupported cache mode: %s", policy) +} + // defaultAname is the default attach name. const defaultAname = "/" @@ -206,11 +212,12 @@ func options(data string) (opts, error) { // Parse the cache policy. Reject unsupported policies. o.policy = cacheAll - if cp, ok := options[cacheKey]; ok { - if cachePolicy(cp) != cacheAll && cachePolicy(cp) != cacheNone { - return o, fmt.Errorf("unsupported cache mode: 'cache=%s'", cp) + if policy, ok := options[cacheKey]; ok { + cp, err := parseCachePolicy(policy) + if err != nil { + return o, err } - o.policy = cachePolicy(cp) + o.policy = cp delete(options, cacheKey) } |