/[fuse.before_github]/perl/trunk/examples/rmount.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /perl/trunk/examples/rmount.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 19 - (hide annotations)
Tue Dec 27 12:47:00 2005 UTC (18 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 1742 byte(s)
Changes from Mark Glines in preparation for 0.07
- Remove the FUSE_DEBUG constant; we never actually implemented
  it to begin with.
- "make test" now uses the version of Fuse you've just built,
  not the one installed in /usr/lib/perl5.
- getattr test now allows blksize to vary between host and fuse
  fs, as this is not a bug.
- Add experimental support for threading.  The following minor
  API changes accommodate this:
- The nonexistent (yet documented) "unthreaded=>1" attribute
  has been replaced with the "threaded=>1" attribute, and this
  time it actually exists.
- Symbolic refs like "main::e_getattr" are now allowed for
  callbacks, because threaded mode needs to share() the
  callbacks, yet perl 5.8.7 does not allow share()ing code
  refs yet.  Direct code-refs are still supported as much
  as possible (currently, non-threaded mode).
- testsuite uses a multithreaded loopback.pl, when available.
- Update docs accordingly.  Update examples accordingly.

1 dpavlin 19 #!/usr/bin/perl -w
2 mszeredi 4
3 dpavlin 19 # This example needs some work before it can support threads.
4 mszeredi 4 use strict;
5     use Net::SSH 'sshopen2';
6     use IPC::Open2;
7     use Fuse;
8     use Data::Dumper;
9    
10     my ($host, $dir, $mount) = @ARGV;
11     if(!defined($mount)) {
12     $mount = $dir;
13     if($host =~ /^(.*):(.*)$/) {
14     ($host,$dir) = ($1,$2);
15     } else {
16     die "usage: $0 user\@host remotedir mountpoint\n".
17     "or : $0 user\@host:remotedir mountpoint\n";
18     }
19     }
20    
21     `umount $mount` unless -d $mount;
22     die "mountpoint $mount isn't a directory!\n" unless -d $mount;
23    
24     my (%args) = (mountpoint => $mount);
25    
26     map { my ($str) = $_; $args{$str} = sub { netlink($str,@_) } }
27     qw(getattr getdir open read write readlink unlink rmdir
28     symlink rename link chown chmod truncate utime mkdir
29     rmdir mknod statfs);
30    
31     sub connect_remote {
32     sshopen2($host, *READER, *WRITER, "./rmount_remote.pl $dir")
33     or die "ssh: $!\n";
34     select WRITER;
35     $| = 1;
36     select STDOUT;
37     }
38    
39     $SIG{CHLD} = sub {
40     use POSIX ":sys_wait_h";
41     my $kid;
42     do {
43     $kid = waitpid(-1,WNOHANG);
44     } until $kid < 1;
45     };
46    
47     connect_remote;
48    
49     sub netlink {
50     my ($str) = Dumper(\@_)."\n";
51     $str = sprintf("%08i\n%s",length($str),$str);
52     while(1) { # retry as necessary
53     my ($VAR1);
54     $VAR1 = undef;
55     eval {
56 dpavlin 19 local $SIG{ALRM} = sub { die "timeout\n" };
57 mszeredi 4 alarm 10;
58     print WRITER $str;
59     my ($len, $data);
60 dpavlin 19 $data = '';
61     if(sysread(READER,$len,9) == 9) {
62     sysread(READER,$data,$len-length($data),length($data))
63 mszeredi 4 while(length($data) < $len);
64     eval $data;
65     }
66 dpavlin 19 alarm 0;
67 mszeredi 4 };
68     if(defined $VAR1) {
69     return wantarray ? @{$VAR1} : $$VAR1[0];
70     }
71     print STDERR "failed to send command; reconnecting ssh\n";
72     close(READER);
73     close(WRITER);
74     connect_remote();
75     }
76     }
77    
78     Fuse::main(%args);
79    
80     netlink("bye");
81     close(READER);
82     close(WRITER);

  ViewVC Help
Powered by ViewVC 1.1.26