-
Notifications
You must be signed in to change notification settings - Fork 255
9p file sharing #4866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
9p file sharing #4866
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -248,6 +248,7 @@ func configureSharedDirs(vm *virtualMachine, sshRunner *crcssh.Runner) error { | |||||||||||||||||||||||||||||||||
if _, _, err := sshRunner.RunPrivileged(fmt.Sprintf("Mounting %s", mount.Target), "mount", "-o", "context=\"system_u:object_r:container_file_t:s0\"", "-t", mount.Type, mount.Tag, mount.Target); err != nil { | ||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
case "cifs": | ||||||||||||||||||||||||||||||||||
smbUncPath := fmt.Sprintf("//%s/%s", hostVirtualIP, mount.Tag) | ||||||||||||||||||||||||||||||||||
if _, _, err := sshRunner.RunPrivate("sudo", "mount", "-o", fmt.Sprintf("rw,uid=core,gid=core,username='%s',password='%s'", mount.Username, mount.Password), "-t", mount.Type, smbUncPath, mount.Target); err != nil { | ||||||||||||||||||||||||||||||||||
|
@@ -257,6 +258,16 @@ func configureSharedDirs(vm *virtualMachine, sshRunner *crcssh.Runner) error { | |||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return fmt.Errorf("Failed to mount CIFS/SMB share '%s' please make sure configured password is correct: %w", mount.Tag, err) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
case "9p": | ||||||||||||||||||||||||||||||||||
// change owner to core user to allow mounting to it as a non-root user | ||||||||||||||||||||||||||||||||||
if _, _, err := sshRunner.RunPrivileged("Changing owner of mount directory", "chown core:core", mount.Target); err != nil { | ||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
if _, _, err := sshRunner.Run("9pfs 192.168.127.1", mount.Target); err != nil { | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Split the 9pfs command arguments. The command and IP address are passed as a single string, but Apply this diff: - if _, _, err := sshRunner.Run("9pfs 192.168.127.1", mount.Target); err != nil {
+ if _, _, err := sshRunner.Run("9pfs", "192.168.127.1", mount.Target); err != nil { 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
+262
to
+269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the chown command syntax. Line 264 has incorrect argument passing. The command Apply this diff to fix the syntax: case "9p":
// change owner to core user to allow mounting to it as a non-root user
- if _, _, err := sshRunner.RunPrivileged("Changing owner of mount directory", "chown core:core", mount.Target); err != nil {
+ if _, _, err := sshRunner.RunPrivileged("Changing owner of mount directory", "chown", "core:core", mount.Target); err != nil {
return err
}
if _, _, err := sshRunner.Run("9pfs 192.168.127.1", mount.Target); err != nil {
return err
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||
return fmt.Errorf("Unknown Shared dir type requested: %s", mount.Type) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package fs9p | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/DeedleFake/p9" | ||
"github.com/DeedleFake/p9/proto" | ||
"github.com/crc-org/crc/v2/pkg/crc/constants" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type Server struct { | ||
// Listener this server is bound to | ||
Listener net.Listener | ||
// Plan9 Filesystem type that holds the exposed directory | ||
Filesystem p9.FileSystem | ||
// Directory this server exposes | ||
ExposedDir string | ||
// Errors from the server being started will come out here | ||
ErrChan chan error | ||
} | ||
|
||
// New9pServer exposes a single directory (and all children) via the given net.Listener | ||
// and returns the server struct. | ||
// Directory given must be an absolute path and must exist. | ||
func New9pServer(listener net.Listener, exposeDir string) (*Server, error) { | ||
// Verify that exposeDir makes sense. | ||
if !filepath.IsAbs(exposeDir) { | ||
return nil, fmt.Errorf("path to expose to machine must be absolute: %s", exposeDir) | ||
} | ||
stat, err := os.Stat(exposeDir) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot stat path to expose to machine: %w", err) | ||
} | ||
if !stat.IsDir() { | ||
return nil, fmt.Errorf("path to expose to machine must be a directory: %s", exposeDir) | ||
} | ||
|
||
fs := p9.FileSystem(p9.Dir(exposeDir)) | ||
// set size to 1 making channel buffered to prevent proto.Serve blocking | ||
errChan := make(chan error, 1) | ||
|
||
toReturn := new(Server) | ||
toReturn.Listener = listener | ||
toReturn.Filesystem = fs | ||
toReturn.ExposedDir = exposeDir | ||
toReturn.ErrChan = errChan | ||
|
||
return toReturn, nil | ||
} | ||
|
||
// Start a server created by New9pServer. | ||
func (s *Server) Start() error { | ||
go func() { | ||
s.ErrChan <- proto.Serve(s.Listener, p9.Proto(), p9.FSConnHandler(s.Filesystem, constants.Plan9Msize)) | ||
close(s.ErrChan) | ||
}() | ||
|
||
// Just before returning, check to see if we got an error off server startup. | ||
select { | ||
case err := <-s.ErrChan: | ||
return fmt.Errorf("starting 9p server: %w", err) | ||
default: | ||
logrus.Infof("Successfully started 9p server on %s for directory %s", s.Listener.Addr().String(), s.ExposedDir) | ||
return nil | ||
} | ||
} | ||
|
||
// Stop a running server. | ||
// Please note that this does *BAD THINGS* to clients if they are still running | ||
// when the server stops. Processes get stuck in I/O deep sleep and zombify, and | ||
// nothing I do other than restarting the VM can remove the zombies. | ||
func (s *Server) Stop() error { | ||
if err := s.Listener.Close(); err != nil { | ||
return err | ||
} | ||
logrus.Infof("Successfully stopped 9p server for directory %s", s.ExposedDir) | ||
return nil | ||
} | ||
redbeam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// WaitForError from a running server. | ||
func (s *Server) WaitForError() error { | ||
err := <-s.ErrChan | ||
return err | ||
} | ||
redbeam marked this conversation as resolved.
Show resolved
Hide resolved
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.