Skip to content

Commit 32ae274

Browse files
committed
update. fuse
1 parent ed9381f commit 32ae274

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

cli_help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestCLIAppsKeepLoadBearingHelpMetadata(t *testing.T) {
7171
for _, flag := range app.Flags {
7272
flags = append(flags, flag.String())
7373
}
74-
check(t, app.Name, app.Usage, app.Version, flags, []string{"list-mounts", "foreground", "enable-control-master"}, "(beta/transfer)")
74+
check(t, app.Name, app.Usage, app.Version, flags, []string{"list-mounts", "foreground", "debug", "enable-control-master"}, "(beta/transfer)")
7575
}
7676
{
7777
app := app_lspipe.Lspipe()

cmd/lsshfs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OPTIONS:
2525
--host servername, -H servername connect servername.
2626
--file filepath, -F filepath config filepath. (default: "/Users/blacknon/.lssh.conf")
2727
--generate-lssh-conf ~/.ssh/config print generated lssh config from OpenSSH config to stdout (~/.ssh/config by default).
28+
--debug enable debug logging for lsshfs and go-sshlib.
2829
--rw mount as read-write (current default behavior).
2930
--unmount unmount the specified mountpoint and stop the background process.
3031
--list-mounts list active lsshfs mount records.

internal/app/lsshfs/app.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ USAGE:
7575
cli.StringSliceFlag{Name: "host,H", Usage: "connect `servername`."},
7676
cli.StringFlag{Name: "file,F", Value: defConf, Usage: "config `filepath`."},
7777
cli.StringFlag{Name: "generate-lssh-conf", Usage: "print generated lssh config from OpenSSH config to stdout (`~/.ssh/config` by default)."},
78+
cli.BoolFlag{Name: "debug", Usage: "enable debug logging for lsshfs and go-sshlib."},
7879
cli.BoolFlag{Name: "rw", Usage: "mount as read-write (current default behavior)."},
7980
cli.BoolFlag{Name: "unmount", Usage: "unmount the specified mountpoint and stop the background process."},
8081
cli.BoolFlag{Name: "list-mounts", Usage: "list active lsshfs mount records."},
@@ -85,6 +86,11 @@ USAGE:
8586
app.Flags = append(app.Flags, common.ControlMasterOverrideFlags()...)
8687

8788
app.Action = func(c *cli.Context) error {
89+
if c.Bool("debug") {
90+
_ = os.Setenv("GO_SSHLIB_DEBUG", "1")
91+
_ = os.Setenv("LSSHFS_DEBUG", "1")
92+
}
93+
8894
if c.Bool("help") {
8995
cli.ShowAppHelp(c)
9096
os.Exit(0)

internal/lsshfs/runner.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ type mountConn interface {
5454
CheckClientAlive() error
5555
}
5656

57+
func (r *Runner) debugEnabled() bool {
58+
switch os.Getenv("LSSHFS_DEBUG") {
59+
case "1", "true", "TRUE", "yes", "YES", "on", "ON":
60+
return true
61+
default:
62+
return false
63+
}
64+
}
65+
66+
func (r *Runner) debugf(format string, args ...interface{}) {
67+
if !r.debugEnabled() {
68+
return
69+
}
70+
_, _ = fmt.Fprintf(r.Stderr, "DEBUG lsshfs: "+format+"\n", args...)
71+
}
72+
5773
func (r *Runner) Run() error {
5874
if r.Stdout == nil {
5975
r.Stdout = os.Stdout
@@ -84,6 +100,7 @@ func (r *Runner) Run() error {
84100
if err != nil {
85101
return err
86102
}
103+
r.debugf("start host=%s remote_path=%s mountpoint=%s goos=%s backend=%s", r.Host, r.RemotePath, r.MountPoint, r.GOOS, backend)
87104

88105
mountpoint, err := normalizeMountPoint(r.GOOS, r.MountPoint)
89106
if err != nil {
@@ -102,6 +119,7 @@ func (r *Runner) Run() error {
102119
return err
103120
}
104121
defer connect.Close()
122+
r.debugf("ssh connection established host=%s", r.Host)
105123

106124
record := MountRecord{
107125
Host: r.Host,
@@ -115,24 +133,30 @@ func (r *Runner) Run() error {
115133
return err
116134
}
117135
defer removeMountRecord(r.MountPoint)
136+
r.debugf("mount record written mountpoint=%s", r.MountPoint)
118137

119138
var cleanupOnce sync.Once
120139
cleanup := func() {
121140
cleanupOnce.Do(func() {
141+
r.debugf("cleanup start mountpoint=%s", r.MountPoint)
122142
if commands, err := unmountCommands(r.GOOS, r.MountPoint); err == nil {
123143
for _, command := range commands {
144+
r.debugf("cleanup command name=%s args=%v", command.Name, command.Args)
124145
if err := r.runCommand(command); err == nil {
146+
r.debugf("cleanup command succeeded name=%s", command.Name)
125147
break
126148
}
127149
}
128150
}
129151
_ = connect.Close()
152+
r.debugf("cleanup complete mountpoint=%s", r.MountPoint)
130153
})
131154
}
132155

133156
serveErrCh := make(chan error, 1)
134157
switch backend {
135158
case BackendFUSE:
159+
r.debugf("starting FUSE forward mountpoint=%s remote_path=%s", r.MountPoint, r.RemotePath)
136160
go func() {
137161
serveErrCh <- connect.FUSEForward(r.MountPoint, r.RemotePath)
138162
}()
@@ -168,6 +192,7 @@ func (r *Runner) Run() error {
168192
select {
169193
case err := <-serveErrCh:
170194
if err != nil {
195+
r.debugf("serve loop exited before mount became active err=%v", err)
171196
cleanup()
172197
return err
173198
}
@@ -177,11 +202,14 @@ func (r *Runner) Run() error {
177202
}
178203

179204
if err := r.waitForMountActive(r.GOOS, r.MountPoint, defaultMountActiveTimeout); err != nil {
205+
r.debugf("mount did not become active mountpoint=%s err=%v", r.MountPoint, err)
180206
cleanup()
181207
return err
182208
}
209+
r.debugf("mount active mountpoint=%s", r.MountPoint)
183210

184211
if r.ReadyNotifier != nil {
212+
r.debugf("notify ready mountpoint=%s", r.MountPoint)
185213
r.ReadyNotifier()
186214
}
187215

@@ -201,11 +229,13 @@ func (r *Runner) Run() error {
201229
for {
202230
select {
203231
case err := <-serveErrCh:
232+
r.debugf("serve loop exited mountpoint=%s err=%v", r.MountPoint, err)
204233
cleanup()
205234
return err
206235
case <-ticker.C:
207236
if err := connect.CheckClientAlive(); err != nil {
208237
aliveFailures++
238+
r.debugf("alive check failed count=%d limit=%d err=%v", aliveFailures, r.aliveFailureLimit, err)
209239
if aliveFailures >= r.aliveFailureLimit {
210240
fmt.Fprintf(r.Stderr, "Information : ssh connection lost, unmounting %s\n", r.MountPoint)
211241
cleanup()
@@ -214,7 +244,9 @@ func (r *Runner) Run() error {
214244
continue
215245
}
216246
aliveFailures = 0
247+
r.debugf("alive check ok mountpoint=%s", r.MountPoint)
217248
case <-sigCh:
249+
r.debugf("signal received mountpoint=%s", r.MountPoint)
218250
cleanup()
219251
return nil
220252
}
@@ -240,15 +272,19 @@ func (r *Runner) mountWithRetry(spec CommandSpec, serveErrCh <-chan error) error
240272
var lastErr error
241273

242274
for i := 0; i < defaultMountRetryCount; i++ {
275+
r.debugf("mount attempt=%d name=%s args=%v", i+1, spec.Name, spec.Args)
243276
if err := r.runCommand(spec); err == nil {
277+
r.debugf("mount attempt=%d succeeded", i+1)
244278
return nil
245279
} else {
246280
lastErr = err
281+
r.debugf("mount attempt=%d failed err=%v", i+1, err)
247282
}
248283

249284
select {
250285
case err := <-serveErrCh:
251286
if err != nil {
287+
r.debugf("serve loop exited during mount retry err=%v", err)
252288
return err
253289
}
254290
return nil
@@ -270,5 +306,6 @@ func (r *Runner) runCommand(spec CommandSpec) error {
270306
cmd.Stdin = os.Stdin
271307
cmd.Stdout = r.Stdout
272308
cmd.Stderr = r.Stderr
309+
r.debugf("run command name=%s args=%v", spec.Name, spec.Args)
273310
return cmd.Run()
274311
}

0 commit comments

Comments
 (0)