/[42-fs]/42-lvm.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

Contents of /42-lvm.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations)
Sun Jul 19 15:17:55 2009 UTC (10 years, 4 months ago) by dpavlin
File MIME type: text/plain
File size: 1848 byte(s)
_ doesn't get doubled in device mapper name

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use File::Slurp;
7 use File::Path;
8 use Getopt::Long;
9 use Data::Dump qw/dump/;
10
11 my $dev = '/dev/sdb';
12 my $mnt = '/mnt/42';
13
14 my ( $verbose, $skip, $init, $debug ) = ( 0, 1 );
15
16 GetOptions(
17 'verbose!' => \$verbose,
18 'skip!' => \$skip,
19 'init!' => \$init,
20 'debug!' => \$debug,
21 ) or die "unknown options: $!";
22
23 my $vg = '42';
24
25 sub mount_42 {
26 my $node = "/dev/$vg/_meta";
27 if ( ! -e $node ) {
28 print STDERR "wait for $node";
29 sleep 1;
30 while ( ! -e $node ) {
31 print STDERR ".";
32 sleep 1;
33 }
34 print STDERR " ready\n";
35 }
36 warn "+ mount $node $mnt\n";
37 system("mount $node $mnt") == 0 or die "can't mount: $!";
38 }
39
40 if ( $init ) {
41 system("umount $mnt");
42 system("pvcreate $dev");
43 system("vgcreate $vg $dev");
44 system("lvcreate -n _meta -L 42M $vg");
45 system("mkfs.ext2 /dev/$vg/_meta");
46 mount_42;
47
48 my $cmd = read_file($0);
49 my $path = "$mnt/42.pl";
50 write_file( $path, $cmd );
51 chmod 0755, $path;
52 print "created $path ",-s $path, " bytes\n";
53 exit;
54 }
55
56 map { mkdir $_ unless -e $_ } map { "$mnt/$_" } ( 'log', 'fs', 'stat' );
57
58 my $path = shift @ARGV || die "usage: $0 /path/to/file\n";
59
60 my ($dir,$file) = ($1,$2) if $path =~ m{^(?:(.+)/)?([^/]+)};
61
62 my $fs = "$mnt/fs/$dir";
63 mkpath $fs unless -e $fs;
64
65 $fs .= '/' . $file;
66 if ( -e $fs ) {
67 if ( $skip ) {
68 warn "SKIP $fs\n";
69 exit 0;
70 } else {
71 die "$fs exists! re-run with --skip\n";
72 }
73 }
74
75 my @stat = stat($path);
76 die "can't stat $path: $!" unless @stat;
77 warn "# $path ",$stat[7],$/;
78
79 my $size = $stat[7] / 1024;
80 $size .= 'k';
81
82 my $lv = $file;
83 $lv =~ s{\W+}{_}g;
84
85 system("lvcreate -n $lv -L $size $vg");
86
87 write_file( "$mnt/stat/$file", join("\n",@stat) );
88
89 my $log = "$mnt/log/$file";
90
91 my $to = "/dev/$vg/$lv";
92 symlink( $to , $fs ) || die "can't create $fs: $!";
93
94 my $cmd = "dd_rescue -w -l $log \"$path\" $to";
95 print "+ $cmd\n";
96 exec $cmd;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26