file_set_contents($filename, $content);
};
+sub systemd_escape {
+ my ($val) = @_;
+
+ # NOTE: this is not complete, but enough for our needs. normally all
+ # characters which are not alpha-numerical, '.' or '_' would need escaping
+ $val =~ s/\-/\\x2d/g;
+
+ return $val;
+}
+
+sub systemd_unescape {
+ my ($val) = @_;
+
+ $val =~ s/\\x([a-fA-F0-9]{2})/chr(hex($1))/eg;
+
+ return $val;
+}
+
__PACKAGE__->register_method ({
name => 'index',
path => '',
dir_glob_foreach('/etc/systemd/system', '^mnt-pve-(.+)\.mount$', sub {
my ($filename, $storid) = @_;
+ $storid = systemd_unescape($storid);
my $unitfile = "/etc/systemd/system/$filename";
my $unit = $read_ini->($unitfile);
my $type = $param->{filesystem} // 'ext4';
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
- die "device $dev is already in use\n" if PVE::Diskmanage::disk_is_used($dev);
-
- my $cfg = PVE::Storage::config();
-
- if (my $scfg = PVE::Storage::storage_config($cfg, $name, 1)) {
- die "storage ID '$name' already defined\n";
- }
+ PVE::Diskmanage::assert_disk_unused($dev);
+ PVE::Storage::assert_sid_unused($name) if $param->{add_storage};
my $worker = sub {
my $path = "/mnt/pve/$name";
- my $mountunitname = "mnt-pve-$name.mount";
+ my $mountunitname = "mnt-pve-".systemd_escape($name).".mount";
my $mountunitpath = "/etc/systemd/system/$mountunitname";
PVE::Diskmanage::locked_disk_action(sub {
my $storage_params = {
type => 'dir',
storage => $name,
- content => 'rootdir,images,iso,backup,vztmpl',
+ content => 'rootdir,images,iso,backup,vztmpl,snippets',
is_mountpoint => 1,
path => $path,
nodes => $node,