Add files missing for FreeBSD compilation
parent
6ef3faf6a2
commit
e3472b6da0
|
@ -0,0 +1,26 @@
|
||||||
|
// +build linux, !gendocs
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package constants
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultMountDir is the default mount dir
|
||||||
|
var DefaultMountDir = homedir.HomeDir()
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package driver
|
||||||
|
|
||||||
|
import "os/exec"
|
||||||
|
|
||||||
|
// supportedDrivers is a list of supported drivers on Darwin.
|
||||||
|
var supportedDrivers = []string{
|
||||||
|
VirtualBox,
|
||||||
|
}
|
||||||
|
|
||||||
|
func VBoxManagePath() string {
|
||||||
|
cmd := "VBoxManage"
|
||||||
|
if path, err := exec.LookPath(cmd); err == nil {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
|
@ -0,0 +1,168 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package tunnel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (router *osRouter) EnsureRouteIsAdded(route *Route) error {
|
||||||
|
exists, err := isValidToAddOrDelete(router, route)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceCIDR := route.DestCIDR.String()
|
||||||
|
gatewayIP := route.Gateway.String()
|
||||||
|
|
||||||
|
glog.Infof("Adding route for CIDR %s to gateway %s", serviceCIDR, gatewayIP)
|
||||||
|
command := exec.Command("sudo", "route", "-n", "add", serviceCIDR, gatewayIP)
|
||||||
|
glog.Infof("About to run command: %s", command.Args)
|
||||||
|
stdInAndOut, err := command.CombinedOutput()
|
||||||
|
message := fmt.Sprintf("%s", stdInAndOut)
|
||||||
|
re := regexp.MustCompile(fmt.Sprintf("add net (.*): gateway %s\n", gatewayIP))
|
||||||
|
if !re.MatchString(message) {
|
||||||
|
return fmt.Errorf("error adding Route: %s, %d", message, len(strings.Split(message, "\n")))
|
||||||
|
}
|
||||||
|
glog.Infof("%s", stdInAndOut)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (router *osRouter) Inspect(route *Route) (exists bool, conflict string, overlaps []string, err error) {
|
||||||
|
cmd := exec.Command("netstat", "-nr", "-f", "inet")
|
||||||
|
cmd.Env = append(cmd.Env, "LC_ALL=C")
|
||||||
|
stdInAndOut, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("error running '%v': %s", cmd, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rt := router.parseTable(stdInAndOut)
|
||||||
|
|
||||||
|
exists, conflict, overlaps = rt.Check(route)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (router *osRouter) parseTable(table []byte) routingTable {
|
||||||
|
t := routingTable{}
|
||||||
|
skip := true
|
||||||
|
for _, line := range strings.Split(string(table), "\n") {
|
||||||
|
// header
|
||||||
|
if strings.HasPrefix(line, "Destination") {
|
||||||
|
skip = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// don't care about the 0.0.0.0 routes
|
||||||
|
if skip || strings.HasPrefix(line, "default") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fields := strings.Fields(line)
|
||||||
|
|
||||||
|
if len(fields) <= 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dstCIDRString := router.padCIDR(fields[0])
|
||||||
|
gatewayIPString := fields[1]
|
||||||
|
gatewayIP := net.ParseIP(gatewayIPString)
|
||||||
|
|
||||||
|
_, ipNet, err := net.ParseCIDR(dstCIDRString)
|
||||||
|
if err != nil {
|
||||||
|
glog.V(4).Infof("skipping line: can't parse CIDR from routing table: %s", dstCIDRString)
|
||||||
|
} else if gatewayIP == nil {
|
||||||
|
glog.V(4).Infof("skipping line: can't parse IP from routing table: %s", gatewayIPString)
|
||||||
|
} else {
|
||||||
|
tableLine := routingTableLine{
|
||||||
|
route: &Route{
|
||||||
|
DestCIDR: ipNet,
|
||||||
|
Gateway: gatewayIP,
|
||||||
|
},
|
||||||
|
line: line,
|
||||||
|
}
|
||||||
|
t = append(t, tableLine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func (router *osRouter) padCIDR(origCIDR string) string {
|
||||||
|
s := ""
|
||||||
|
dots := 0
|
||||||
|
slash := false
|
||||||
|
for i, c := range origCIDR {
|
||||||
|
if c == '.' {
|
||||||
|
dots++
|
||||||
|
}
|
||||||
|
if c == '/' {
|
||||||
|
for dots < 3 {
|
||||||
|
s += ".0"
|
||||||
|
dots++
|
||||||
|
}
|
||||||
|
slash = true
|
||||||
|
}
|
||||||
|
if i == len(origCIDR)-1 {
|
||||||
|
s += string(c)
|
||||||
|
bits := 32 - 8*(3-dots)
|
||||||
|
for dots < 3 {
|
||||||
|
s += ".0"
|
||||||
|
dots++
|
||||||
|
}
|
||||||
|
if !slash {
|
||||||
|
s += fmt.Sprintf("/%d", bits)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s += string(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (router *osRouter) Cleanup(route *Route) error {
|
||||||
|
glog.V(3).Infof("Cleaning up %s\n", route)
|
||||||
|
exists, err := isValidToAddOrDelete(router, route)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cmd := exec.Command("sudo", "route", "-n", "delete", route.DestCIDR.String())
|
||||||
|
stdInAndOut, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
msg := fmt.Sprintf("%s", stdInAndOut)
|
||||||
|
glog.V(4).Infof("%s", msg)
|
||||||
|
re := regexp.MustCompile("^delete net ([^:]*)$")
|
||||||
|
if !re.MatchString(msg) {
|
||||||
|
return fmt.Errorf("error deleting route: %s, %d", msg, len(strings.Split(msg, "\n")))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright 2009 The go9p Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package go9p
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (dir *pipeDir) dotu(path string, d os.FileInfo, upool Users, sysMode *syscall.Stat_t) {
|
||||||
|
u := upool.Uid2User(int(sysMode.Uid))
|
||||||
|
g := upool.Gid2Group(int(sysMode.Gid))
|
||||||
|
dir.Uid = u.Name()
|
||||||
|
if dir.Uid == "" {
|
||||||
|
dir.Uid = "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
dir.Gid = g.Name()
|
||||||
|
if dir.Gid == "" {
|
||||||
|
dir.Gid = "none"
|
||||||
|
}
|
||||||
|
dir.Muid = "none"
|
||||||
|
dir.Ext = ""
|
||||||
|
dir.Uidnum = uint32(u.Id())
|
||||||
|
dir.Gidnum = uint32(g.Id())
|
||||||
|
dir.Muidnum = NOUID
|
||||||
|
if d.Mode()&os.ModeSymlink != 0 {
|
||||||
|
var err error
|
||||||
|
dir.Ext, err = os.Readlink(path)
|
||||||
|
if err != nil {
|
||||||
|
dir.Ext = ""
|
||||||
|
}
|
||||||
|
} else if isBlock(d) {
|
||||||
|
dir.Ext = fmt.Sprintf("b %d %d", sysMode.Rdev>>24, sysMode.Rdev&0xFFFFFF)
|
||||||
|
} else if isChar(d) {
|
||||||
|
dir.Ext = fmt.Sprintf("c %d %d", sysMode.Rdev>>24, sysMode.Rdev&0xFFFFFF)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,239 @@
|
||||||
|
// Copyright 2009 The go9p Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package go9p
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func atime(stat *syscall.Stat_t) time.Time {
|
||||||
|
return time.Unix(stat.Atimespec.Unix())
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBlock reports if the file is a block device
|
||||||
|
func isBlock(d os.FileInfo) bool {
|
||||||
|
stat := d.Sys().(*syscall.Stat_t)
|
||||||
|
return (stat.Mode & syscall.S_IFMT) == syscall.S_IFBLK
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsChar reports if the file is a character device
|
||||||
|
func isChar(d os.FileInfo) bool {
|
||||||
|
stat := d.Sys().(*syscall.Stat_t)
|
||||||
|
return (stat.Mode & syscall.S_IFMT) == syscall.S_IFCHR
|
||||||
|
}
|
||||||
|
|
||||||
|
func dir2Qid(d os.FileInfo) *Qid {
|
||||||
|
var qid Qid
|
||||||
|
|
||||||
|
qid.Path = d.Sys().(*syscall.Stat_t).Ino
|
||||||
|
qid.Version = uint32(d.ModTime().UnixNano() / 1000000)
|
||||||
|
qid.Type = dir2QidType(d)
|
||||||
|
|
||||||
|
return &qid
|
||||||
|
}
|
||||||
|
|
||||||
|
func dir2Dir(path string, d os.FileInfo, dotu bool, upool Users) (*Dir, error) {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
fmt.Print("stat failed: ", r)
|
||||||
|
return nil, &os.PathError{"dir2Dir", path, nil}
|
||||||
|
}
|
||||||
|
sysif := d.Sys()
|
||||||
|
if sysif == nil {
|
||||||
|
return nil, &os.PathError{"dir2Dir: sysif is nil", path, nil}
|
||||||
|
}
|
||||||
|
sysMode := sysif.(*syscall.Stat_t)
|
||||||
|
|
||||||
|
dir := new(ufsDir)
|
||||||
|
dir.Qid = *dir2Qid(d)
|
||||||
|
dir.Mode = dir2Npmode(d, dotu)
|
||||||
|
dir.Atime = uint32(0 /*atime(sysMode).Unix()*/)
|
||||||
|
dir.Mtime = uint32(d.ModTime().Unix())
|
||||||
|
dir.Length = uint64(d.Size())
|
||||||
|
dir.Name = path[strings.LastIndex(path, "/")+1:]
|
||||||
|
|
||||||
|
if dotu {
|
||||||
|
dir.dotu(path, d, upool, sysMode)
|
||||||
|
return &dir.Dir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
unixUid := int(sysMode.Uid)
|
||||||
|
unixGid := int(sysMode.Gid)
|
||||||
|
dir.Uid = strconv.Itoa(unixUid)
|
||||||
|
dir.Gid = strconv.Itoa(unixGid)
|
||||||
|
|
||||||
|
// BUG(akumar): LookupId will never find names for
|
||||||
|
// groups, as it only operates on user ids.
|
||||||
|
u, err := user.LookupId(dir.Uid)
|
||||||
|
if err == nil {
|
||||||
|
dir.Uid = u.Username
|
||||||
|
}
|
||||||
|
g, err := user.LookupId(dir.Gid)
|
||||||
|
if err == nil {
|
||||||
|
dir.Gid = g.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For Akaros, we use the Muid as the link value. */
|
||||||
|
if *Akaros && (d.Mode()&os.ModeSymlink != 0) {
|
||||||
|
dir.Muid, err = os.Readlink(path)
|
||||||
|
if err == nil {
|
||||||
|
dir.Mode |= DMSYMLINK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &dir.Dir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dir *ufsDir) dotu(path string, d os.FileInfo, upool Users, sysMode *syscall.Stat_t) {
|
||||||
|
u := upool.Uid2User(int(sysMode.Uid))
|
||||||
|
g := upool.Gid2Group(int(sysMode.Gid))
|
||||||
|
dir.Uid = u.Name()
|
||||||
|
if dir.Uid == "" {
|
||||||
|
dir.Uid = "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
dir.Gid = g.Name()
|
||||||
|
if dir.Gid == "" {
|
||||||
|
dir.Gid = "none"
|
||||||
|
}
|
||||||
|
dir.Muid = "none"
|
||||||
|
dir.Ext = ""
|
||||||
|
dir.Uidnum = uint32(u.Id())
|
||||||
|
dir.Gidnum = uint32(g.Id())
|
||||||
|
dir.Muidnum = NOUID
|
||||||
|
if d.Mode()&os.ModeSymlink != 0 {
|
||||||
|
var err error
|
||||||
|
dir.Ext, err = os.Readlink(path)
|
||||||
|
if err != nil {
|
||||||
|
dir.Ext = ""
|
||||||
|
}
|
||||||
|
} else if isBlock(d) {
|
||||||
|
dir.Ext = fmt.Sprintf("b %d %d", sysMode.Rdev>>24, sysMode.Rdev&0xFFFFFF)
|
||||||
|
} else if isChar(d) {
|
||||||
|
dir.Ext = fmt.Sprintf("c %d %d", sysMode.Rdev>>24, sysMode.Rdev&0xFFFFFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *Ufs) Wstat(req *SrvReq) {
|
||||||
|
fid := req.Fid.Aux.(*ufsFid)
|
||||||
|
err := fid.stat()
|
||||||
|
if err != nil {
|
||||||
|
req.RespondError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := &req.Tc.Dir
|
||||||
|
if dir.Mode != 0xFFFFFFFF {
|
||||||
|
mode := dir.Mode & 0777
|
||||||
|
if req.Conn.Dotu {
|
||||||
|
if dir.Mode&DMSETUID > 0 {
|
||||||
|
mode |= syscall.S_ISUID
|
||||||
|
}
|
||||||
|
if dir.Mode&DMSETGID > 0 {
|
||||||
|
mode |= syscall.S_ISGID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e := os.Chmod(fid.path, os.FileMode(mode))
|
||||||
|
if e != nil {
|
||||||
|
req.RespondError(toError(e))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uid, gid := NOUID, NOUID
|
||||||
|
if req.Conn.Dotu {
|
||||||
|
uid = dir.Uidnum
|
||||||
|
gid = dir.Gidnum
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to find local uid, gid by name.
|
||||||
|
if (dir.Uid != "" || dir.Gid != "") && !req.Conn.Dotu {
|
||||||
|
uid, err = lookup(dir.Uid, false)
|
||||||
|
if err != nil {
|
||||||
|
req.RespondError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BUG(akumar): Lookup will never find gids
|
||||||
|
// corresponding to group names, because
|
||||||
|
// it only operates on user names.
|
||||||
|
gid, err = lookup(dir.Gid, true)
|
||||||
|
if err != nil {
|
||||||
|
req.RespondError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if uid != NOUID || gid != NOUID {
|
||||||
|
e := os.Chown(fid.path, int(uid), int(gid))
|
||||||
|
if e != nil {
|
||||||
|
req.RespondError(toError(e))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if dir.Name != "" {
|
||||||
|
fmt.Printf("Rename %s to %s\n", fid.path, dir.Name)
|
||||||
|
// if first char is / it is relative to root, else relative to
|
||||||
|
// cwd.
|
||||||
|
var destpath string
|
||||||
|
if dir.Name[0] == '/' {
|
||||||
|
destpath = path.Join(u.Root, dir.Name)
|
||||||
|
fmt.Printf("/ results in %s\n", destpath)
|
||||||
|
} else {
|
||||||
|
fiddir, _ := path.Split(fid.path)
|
||||||
|
destpath = path.Join(fiddir, dir.Name)
|
||||||
|
fmt.Printf("rel results in %s\n", destpath)
|
||||||
|
}
|
||||||
|
err := os.Rename(fid.path, destpath)
|
||||||
|
fmt.Printf("rename %s to %s gets %v\n", fid.path, destpath, err)
|
||||||
|
if err != nil {
|
||||||
|
req.RespondError(toError(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fid.path = destpath
|
||||||
|
}
|
||||||
|
|
||||||
|
if dir.Length != 0xFFFFFFFFFFFFFFFF {
|
||||||
|
e := os.Truncate(fid.path, int64(dir.Length))
|
||||||
|
if e != nil {
|
||||||
|
req.RespondError(toError(e))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If either mtime or atime need to be changed, then
|
||||||
|
// we must change both.
|
||||||
|
if dir.Mtime != ^uint32(0) || dir.Atime != ^uint32(0) {
|
||||||
|
mt, at := time.Unix(int64(dir.Mtime), 0), time.Unix(int64(dir.Atime), 0)
|
||||||
|
if cmt, cat := (dir.Mtime == ^uint32(0)), (dir.Atime == ^uint32(0)); cmt || cat {
|
||||||
|
st, e := os.Stat(fid.path)
|
||||||
|
if e != nil {
|
||||||
|
req.RespondError(toError(e))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch cmt {
|
||||||
|
case true:
|
||||||
|
mt = st.ModTime()
|
||||||
|
default:
|
||||||
|
// at = time.Time(0)//atime(st.Sys().(*syscall.Stat_t))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// macOS filesystem st_mtime values are only accurate to the second
|
||||||
|
// this ensures, 9p will only write mtime to the second #1375
|
||||||
|
e := os.Chtimes(fid.path, at.Truncate(time.Second), mt.Truncate(time.Second))
|
||||||
|
if e != nil {
|
||||||
|
req.RespondError(toError(e))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.RespondRwstat()
|
||||||
|
}
|
Loading…
Reference in New Issue