Skip to content

Commit c8c6eed

Browse files
authored
Merge pull request #5641 from thaJeztah/move_sys_fmountat
move sys.FMountat() into mount package and un-export
2 parents 03bfcd8 + a964cf0 commit c8c6eed

5 files changed

Lines changed: 10 additions & 11 deletions

File tree

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package sys
17+
package mount
1818

1919
import (
2020
"runtime"
@@ -26,8 +26,8 @@ import (
2626
"golang.org/x/sys/unix"
2727
)
2828

29-
// FMountat performs mount from the provided directory.
30-
func FMountat(dirfd uintptr, source, target, fstype string, flags uintptr, data string) error {
29+
// fMountat performs mount from the provided directory.
30+
func fMountat(dirfd uintptr, source, target, fstype string, flags uintptr, data string) error {
3131
var (
3232
sourceP, targetP, fstypeP, dataP *byte
3333
pid uintptr
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package sys
17+
package mount
1818

1919
import (
2020
"io/ioutil"
@@ -32,7 +32,7 @@ import (
3232
type fMountatCaseFunc func(t *testing.T, root string)
3333

3434
func TestFMountat(t *testing.T) {
35-
if !runningPrivileged() {
35+
if unix.Geteuid() != 0 {
3636
t.Skip("Needs to be run as root")
3737
return
3838
}
@@ -88,7 +88,7 @@ func testFMountatNormal(t *testing.T, root string) {
8888
defer f.Close()
8989

9090
// mount work to fs
91-
if err = FMountat(f.Fd(), workdir, "fs", "bind", unix.MS_BIND|unix.MS_RDONLY, ""); err != nil {
91+
if err = fMountat(f.Fd(), workdir, "fs", "bind", unix.MS_BIND|unix.MS_RDONLY, ""); err != nil {
9292
t.Fatalf("expected no error here, but got error: %+v", err)
9393
}
9494
defer umount(t, fsdir)
@@ -124,7 +124,7 @@ func testFMountatWithFileFd(t *testing.T, root string) {
124124
}
125125
defer f.Close()
126126

127-
err = FMountat(f.Fd(), filepath.Join(root, "empty"), filepath.Join(root, "work"), "", 0, "")
127+
err = fMountat(f.Fd(), filepath.Join(root, "empty"), filepath.Join(root, "work"), "", 0, "")
128128
if !errors.Is(err, expectedErr) {
129129
t.Fatalf("expected error %v, but got %v", expectedErr, errors.Cause(err))
130130
}
@@ -145,7 +145,7 @@ func testFMountatWithInvalidSource(t *testing.T, root string) {
145145
}
146146
defer f.Close()
147147

148-
err = FMountat(f.Fd(), filepath.Join(root, "oops"), "at", "bind", unix.MS_BIND, "")
148+
err = fMountat(f.Fd(), filepath.Join(root, "oops"), "at", "bind", unix.MS_BIND, "")
149149
if !errors.Is(err, expectedErr) {
150150
t.Fatalf("expected error %v, but got %v", expectedErr, err)
151151
}

mount/mount_linux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"strings"
2525
"time"
2626

27-
"github.com/containerd/containerd/sys"
2827
"github.com/pkg/errors"
2928
"golang.org/x/sys/unix"
3029
)
@@ -378,7 +377,7 @@ func mountAt(chdir string, source, target, fstype string, flags uintptr, data st
378377
if !fs.IsDir() {
379378
return errors.Wrap(errors.Errorf("%s is not dir", chdir), "failed to mountat")
380379
}
381-
return errors.Wrap(sys.FMountat(f.Fd(), source, target, fstype, flags, data), "failed to mountat")
380+
return errors.Wrap(fMountat(f.Fd(), source, target, fstype, flags, data), "failed to mountat")
382381
}
383382

384383
func (m *Mount) mountWithHelper(helperBinary, typePrefix, target string) error {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package sys
17+
package mount
1818

1919
import (
2020
_ "unsafe" // required for go:linkname.

0 commit comments

Comments
 (0)