Merge pull request #5641 from thaJeztah/move_sys_fmountat

move sys.FMountat() into mount package and un-export
This commit is contained in:
Fu Wei 2021-06-24 22:16:48 +08:00 committed by GitHub
commit c8c6eed932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 11 deletions

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package sys package mount
import ( import (
"runtime" "runtime"
@ -26,8 +26,8 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
// FMountat performs mount from the provided directory. // fMountat performs mount from the provided directory.
func FMountat(dirfd uintptr, source, target, fstype string, flags uintptr, data string) error { func fMountat(dirfd uintptr, source, target, fstype string, flags uintptr, data string) error {
var ( var (
sourceP, targetP, fstypeP, dataP *byte sourceP, targetP, fstypeP, dataP *byte
pid uintptr pid uintptr

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package sys package mount
import ( import (
"io/ioutil" "io/ioutil"
@ -32,7 +32,7 @@ import (
type fMountatCaseFunc func(t *testing.T, root string) type fMountatCaseFunc func(t *testing.T, root string)
func TestFMountat(t *testing.T) { func TestFMountat(t *testing.T) {
if !runningPrivileged() { if unix.Geteuid() != 0 {
t.Skip("Needs to be run as root") t.Skip("Needs to be run as root")
return return
} }
@ -88,7 +88,7 @@ func testFMountatNormal(t *testing.T, root string) {
defer f.Close() defer f.Close()
// mount work to fs // mount work to fs
if err = FMountat(f.Fd(), workdir, "fs", "bind", unix.MS_BIND|unix.MS_RDONLY, ""); err != nil { if err = fMountat(f.Fd(), workdir, "fs", "bind", unix.MS_BIND|unix.MS_RDONLY, ""); err != nil {
t.Fatalf("expected no error here, but got error: %+v", err) t.Fatalf("expected no error here, but got error: %+v", err)
} }
defer umount(t, fsdir) defer umount(t, fsdir)
@ -124,7 +124,7 @@ func testFMountatWithFileFd(t *testing.T, root string) {
} }
defer f.Close() defer f.Close()
err = FMountat(f.Fd(), filepath.Join(root, "empty"), filepath.Join(root, "work"), "", 0, "") err = fMountat(f.Fd(), filepath.Join(root, "empty"), filepath.Join(root, "work"), "", 0, "")
if !errors.Is(err, expectedErr) { if !errors.Is(err, expectedErr) {
t.Fatalf("expected error %v, but got %v", expectedErr, errors.Cause(err)) t.Fatalf("expected error %v, but got %v", expectedErr, errors.Cause(err))
} }
@ -145,7 +145,7 @@ func testFMountatWithInvalidSource(t *testing.T, root string) {
} }
defer f.Close() defer f.Close()
err = FMountat(f.Fd(), filepath.Join(root, "oops"), "at", "bind", unix.MS_BIND, "") err = fMountat(f.Fd(), filepath.Join(root, "oops"), "at", "bind", unix.MS_BIND, "")
if !errors.Is(err, expectedErr) { if !errors.Is(err, expectedErr) {
t.Fatalf("expected error %v, but got %v", expectedErr, err) t.Fatalf("expected error %v, but got %v", expectedErr, err)
} }

View File

@ -24,7 +24,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/containerd/containerd/sys"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -378,7 +377,7 @@ func mountAt(chdir string, source, target, fstype string, flags uintptr, data st
if !fs.IsDir() { if !fs.IsDir() {
return errors.Wrap(errors.Errorf("%s is not dir", chdir), "failed to mountat") return errors.Wrap(errors.Errorf("%s is not dir", chdir), "failed to mountat")
} }
return errors.Wrap(sys.FMountat(f.Fd(), source, target, fstype, flags, data), "failed to mountat") return errors.Wrap(fMountat(f.Fd(), source, target, fstype, flags, data), "failed to mountat")
} }
func (m *Mount) mountWithHelper(helperBinary, typePrefix, target string) error { func (m *Mount) mountWithHelper(helperBinary, typePrefix, target string) error {

View File

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
package sys package mount
import ( import (
_ "unsafe" // required for go:linkname. _ "unsafe" // required for go:linkname.