]>
git.proxmox.com Git - pve-storage.git/blob - PVE/Storage/GlusterfsPlugin.pm
1 package PVE
::Storage
::GlusterfsPlugin
;
7 use PVE
::Tools
qw(run_command);
8 use PVE
::Storage
::Plugin
;
9 use PVE
::JSONSchema
qw(get_standard_option);
12 use base
qw(PVE::Storage::Plugin);
14 # Glusterfs helper functions
16 sub read_proc_mounts
{
18 local $/; # enable slurp mode
21 if (my $fd = IO
::File-
>new("/proc/mounts", "r")) {
29 sub glusterfs_is_mounted
{
30 my ($server, $volume, $mountpoint, $mountdata) = @_;
32 my $source = "$server:$volume";
34 $mountdata = read_proc_mounts
() if !$mountdata;
36 if ($mountdata =~ m
|^$source/?\s$mountpoint\sfuse.glusterfs
|m
) {
44 my ($server, $volume, $mountpoint) = @_;
46 my $source = "$server:$volume";
48 my $cmd = ['/bin/mount', '-t', 'glusterfs', $source, $mountpoint];
50 run_command
($cmd, errmsg
=> "mount error");
61 content
=> [ { images
=> 1, rootdir
=> 1, vztmpl
=> 1, iso
=> 1, backup
=> 1},
63 format
=> [ { raw
=> 1, qcow2
=> 1, vmdk
=> 1 } , 'raw' ],
70 description
=> "Glusterfs Volume.",
78 path
=> { fixed
=> 1 },
79 server
=> { optional
=> 1 },
80 volume
=> { fixed
=> 1 },
81 nodes
=> { optional
=> 1 },
82 disable
=> { optional
=> 1 },
83 maxfiles
=> { optional
=> 1 },
84 content
=> { optional
=> 1 },
85 format
=> { optional
=> 1 },
91 my ($class, $sectionId, $config, $create, $skipSchemaCheck) = @_;
93 $config->{path
} = "/mnt/pve/$sectionId" if $create && !$config->{path
};
95 return $class->SUPER::check_config
($sectionId, $config, $create, $skipSchemaCheck);
98 # Storage implementation
101 my ($class, $scfg, $volname, $storeid) = @_;
103 my ($vtype, $name, $vmid) = $class->parse_volname($volname);
105 my $server = $scfg->{server
} ?
$scfg->{server
} : 'localhost';
106 my $glustervolume = $scfg->{volume
};
109 if($vtype eq 'images'){
110 $path = "gluster://$server/$glustervolume/images/$vmid/$name";
112 my $dir = $class->get_subdir($scfg, $vtype);
113 $path = "$dir/$name";
117 return wantarray ?
($path, $vmid, $vtype) : $path;
121 my ($class, $storeid, $scfg, $cache) = @_;
123 $cache->{mountdata
} = read_proc_mounts
() if !$cache->{mountdata
};
125 my $path = $scfg->{path
};
126 my $server = $scfg->{server
} ?
$scfg->{server
} : 'localhost';
128 my $volume = $scfg->{volume
};
130 return undef if !glusterfs_is_mounted
($server, $volume, $path, $cache->{mountdata
});
132 return $class->SUPER::status
($storeid, $scfg, $cache);
135 sub activate_storage
{
136 my ($class, $storeid, $scfg, $cache) = @_;
138 $cache->{mountdata
} = read_proc_mounts
() if !$cache->{mountdata
};
140 my $path = $scfg->{path
};
141 my $server = $scfg->{server
} ?
$scfg->{server
} : 'localhost';
142 my $volume = $scfg->{volume
};
144 if (!glusterfs_is_mounted
($server, $volume, $path, $cache->{mountdata
})) {
148 die "unable to activate storage '$storeid' - " .
149 "directory '$path' does not exist\n" if ! -d
$path;
151 glusterfs_mount
($server, $volume, $path, $scfg->{options
});
154 $class->SUPER::activate_storage
($storeid, $scfg, $cache);
157 sub deactivate_storage
{
158 my ($class, $storeid, $scfg, $cache) = @_;
160 $cache->{mountdata
} = read_proc_mounts
() if !$cache->{mountdata
};
162 my $path = $scfg->{path
};
163 my $server = $scfg->{server
} ?
$scfg->{server
} : 'localhost';
164 my $volume = $scfg->{volume
};
166 if (glusterfs_is_mounted
($server, $volume, $path, $cache->{mountdata
})) {
167 my $cmd = ['/bin/umount', $path];
168 run_command
($cmd, errmsg
=> 'umount error');
172 sub activate_volume
{
173 my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
175 # do nothing by default
178 sub deactivate_volume
{
179 my ($class, $storeid, $scfg, $volname, $cache) = @_;
181 # do nothing by default
184 sub check_connection
{
185 my ($class, $storeid, $scfg) = @_;
187 my $server = $scfg->{server
} ?
$scfg->{server
} : 'localhost';
188 my $volume = $scfg->{volume
};
192 if($server && $server ne 'localhost' && $server ne '127.0.0.1'){
193 my $p = Net
::Ping-
>new("tcp", 2);
194 $status = $p->ping($server);
201 if ($line =~ m/Status: Started$/) {
206 my $cmd = ['/usr/sbin/gluster', 'volume', 'info', $volume];
208 run_command
($cmd, errmsg
=> "glusterfs error", errfunc
=> sub {}, outfunc
=> $parser);