Skip to content

api: add TypeTmpfs to api/types/mount#26837

Merged
vdemeester merged 1 commit intomoby:masterfrom
AkihiroSuda:newtmpfs
Oct 28, 2016
Merged

api: add TypeTmpfs to api/types/mount#26837
vdemeester merged 1 commit intomoby:masterfrom
AkihiroSuda:newtmpfs

Conversation

@AkihiroSuda
Copy link
Member

- What I did
added TypeTmpfs to api/types/mount.

TODO: migrate Swarmkit and CLI to use the new mount API

- How I did it

- How to verify it
TESTFLAGS='-check.f TestContainersApiCreateMounts' make test-integration-cli

- Description for the changelog

api: add TypeTmpfs to api/types/mount

- A picture of a cute animal (not mandatory but encouraged)
penguins

Signed-off-by: Akihiro Suda [email protected]

@AkihiroSuda
Copy link
Member Author

CC @cpuguy83

@justincormack
Copy link
Contributor

cc @stevvooe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have these added to container.Mountpoints now that we have a proper "Type" field.... it would also be helpful to have HostConfig.Tmpfs converted into this format like we are doing (daemon side) for stuff in Binds and Volumes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) We should just group these into a single comment above the const block describing what they are for rather than having these redundant doc strings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think swarmkit is using Mode here.

type Mount_TmpfsOptions struct {
    // Size sets the size of the tmpfs, in bytes.
    //
    // This will be converted to an operating system specific value
    // depending on the host. For example, on linux, it will be convered to
    // use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
    // docker, uses a straight byte value.
    //
    // Percentages are not supported.
    SizeBytes int64 `protobuf:"varint,1,opt,name=size_bytes,json=sizeBytes,proto3" json:"size_bytes,omitempty"`
    // Mode of the tmpfs upon creation
    Mode os.FileMode `protobuf:"varint,2,opt,name=mode,proto3,customtype=os.FileMode" json:"mode"`
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please no more "whatever goes in here, good luck" fields.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'm going to change the struct definition to like this:

// TmpfsOptions defines options specific to mounts of type "tmpfs".                                                                      
type TmpfsOptions struct {
        // Size sets the size of the tmpfs, in bytes.                                                                                    
        //                                                                                                                               
        // This will be converted to an operating system specific value                                                                  
        // depending on the host. For example, on linux, it will be convered to                                                          
        // use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with                                                           
        // docker, uses a straight byte value.                                                                                           
        //                                                                                                                               
        // Percentages are not supported.                                                                                                
        SizeBytes int64
        // Mode of the tmpfs upon creation                                                                                               
        Mode os.FileMode

        // RawOptions is the raw string passed to mount(2).                                                                              
        // e.g. "rw,noexec,nosuid,size=65536k"                                                                                           
        //                                                                                                                               
        // RawOptions is exclusive to other TmpfsOptions fields.                                                                         
        // If RawOptions has a non-empty value, other fields must have empty values.                                                     
        //                                                                                                                               
        // RawOptions can contain "ro" or "rw" but needs to be consistent with                                                           
        // Mount.ReadOnly                                                                                                                
        RawOptions string `json:",omitempty"`
}

I think we need to keep RawOptions for compatibility, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now TmpfsOptions is identical to the corresponding one of Swarmkit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we format these to make them readable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tmpfs linux only? Windows does have ramdisk.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK yes, linux only in the current implementation?
https://github.com/docker/docker/blob/b8265e55508db99aea632033b2f5008f921b11e2/container/container_windows.go#L89-L93

IMO implementation for Windows should be another PR, but I understand we need to design the API with consideration for Windows in this PR.

CC @jhowardmsft

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestContainersAPICreateMountsTmpfs.

Please follow Go's naming conventions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is some project-local naming convention that encourages Test.*Api.*?
If not, perhaps we need to fix that in separate PR?

$ grep "func (.*Suite) Test.*Api" integration-cli/*.go | wc -l
158
$ grep "func (.*Suite) Test.*API" integration-cli/*.go | wc -l
2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed; better done in a separate PR if we want to change that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah This is a new test. It should follow our coding standards.

Demonstrations of others not following the standards does not make it okay to not follow the standards.

Copy link
Member Author

@AkihiroSuda AkihiroSuda Sep 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, and opened PR for existing tests: #26967

@AkihiroSuda
Copy link
Member Author

AkihiroSuda commented Sep 27, 2016

updated PR, please review again if CI green?
@cpuguy83 @stevvooe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to fix this, now fixing..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@AkihiroSuda AkihiroSuda force-pushed the newtmpfs branch 3 times, most recently from a7afeda to 3b8527a Compare September 27, 2016 09:12
@AkihiroSuda
Copy link
Member Author

Failure in windowsRS1 is trivial, I'll make sure it is skipped on Windows

00:48:59.244 ----------------------------------------------------------------------
00:48:59.245 FAIL: docker_api_containers_test.go:1525: DockerSuite.TestContainersApiCreateMountsValidation
00:48:59.245 
00:48:59.245 case 0
00:48:59.245 case 1
00:48:59.245 case 2
00:48:59.245 case 3
00:48:59.245 case 4
00:48:59.245 case 5
00:48:59.245 case 6
00:48:59.245 case 7
00:48:59.245 docker_api_containers_test.go:1711:
00:48:59.245     c.Assert(status, checker.Equals, x.status, check.Commentf("%s\n%v", string(b), cases[i].config))
00:48:59.245 ... obtained int = 400
00:48:59.245 ... expected int = 201
00:48:59.246 ... {"message":"invalid mount config for type \"tmpfs\": Windows does not support tmpfs"}
00:48:59.246 
00:48:59.246 {busybox {[{tmpfs  c:\foo false <nil> <nil> <nil>}]}}
00:48:59.246 
00:48:59.395 
00:48:59.395 ----------------------------------------------------------------------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would there be a source here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please no more "whatever goes in here, good luck" fields.

@AkihiroSuda
Copy link
Member Author

updated PR: removed RawOptions from api/types/mount.TmpfsOptions

// TypeBind BIND
TypeBind Type = "bind"
// TypeVolume VOLUME
TypeBind Type = "bind"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than remove documentation, let's actually add it in. You can copy from swarmkit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

type Mount struct {
Type Type `json:",omitempty"`
Type Type `json:",omitempty"`
// Source is not supported in TMPFS (must be an empty value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is more to Source than just that. This is incomplete.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Mode of the tmpfs upon creation
Mode os.FileMode

UID uint32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are for non-swarm containers, and imo they are still needed for compatibility; old tmpfs allowed these options

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were not supported with tmpfs previously. Do not add them in this PR. You can have a similar comment as I have in swarmkit, but please don't add things that aren't actually supportable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems supported it in Docker 1.12.2, WDYT?

$ docker run -it --rm --tmpfs /foo:uid=4242,nr_inodes=3 busybox
/ # ls -ld /foo
drwxrwxrwt    2 4242     root            40 Oct 14 05:10 /foo
/ # touch /foo/1
/ # touch /foo/2
/ # touch /foo/3
touch: /foo/3: No space left on device

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not currently supported for swarmkit. I am not sure what to say about docker run. These options are in no way portable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I removed them in the latest commit

}
if opt.INodes != 0 {
switch os {
case "linux":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use build tags to do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the code itself

mounttypes "github.com/docker/docker/api/types/mount"
)

func TestRawTmpfsOptions(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no more raw...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

rawOpts = append(rawOpts, fmt.Sprintf("size=%d%s", size, suffix))
}
if opt.UID != 0 {
rawOpts = append(rawOpts, fmt.Sprintf("uid=%d", opt.UID))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO
Check nil instead of zero

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the code itself

GID uint32
Blocks int64
INodes int64
MemoryPolicy string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the contents of MemoryPolicy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it in the latest commit, but it meant mpol for Linux tmpfs

https://linux.die.net/man/8/mount

mpol=[default|prefer:Node|bind:NodeList|interleave|interleave:NodeList]

@AkihiroSuda AkihiroSuda force-pushed the newtmpfs branch 2 times, most recently from e1c9452 to 1af22c3 Compare October 25, 2016 06:33
@AkihiroSuda
Copy link
Member Author

updated PR #26837 (comment)
Please look into this again (if CI green)? @stevvooe @cpuguy83

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty happy with this, just one minor change and I think we'll be ready to roll.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use errExtraField instead of fmt.Errorf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@AkihiroSuda AkihiroSuda mentioned this pull request Oct 27, 2016
4 tasks
@stevvooe
Copy link
Contributor

The fact that Mount.Data exists is disappointing but I don't see how we can remove it.

Thanks for the solid PR!

@thaJeztah
Copy link
Member

ping @AkihiroSuda can you address @cpuguy83's nit (#26837 (comment)), then it looks like we're ready to go

@AkihiroSuda
Copy link
Member Author

@thaJeztah done

@AkihiroSuda
Copy link
Member Author

updated docs/reference/api as well

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Moving to docs review

- **Options** - key/value map of driver specific options.
- **TmpfsOptions** – Optional configuration for the `tmpfs` type.
- **SizeBytes** – The size for the tmpfs mount in bytes.
- **Mode** – The permission mode for the tmpfs mount in an integer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I think we should update the JSON example with some mounts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(because we currently don't have an example in there it seems)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs LGTM, thanks so much @AkihiroSuda!

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants