]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/CIFSPlugin.pm
drbd: comment that the builtin plugin is depreacated
[pve-storage.git] / PVE / Storage / CIFSPlugin.pm
index 6115a967c069ce2de734c99f3c3817db9bad8571..be06cc761e4e7244358ce72379ef50d7e2a93edd 100644 (file)
@@ -30,14 +30,22 @@ sub cifs_is_mounted {
 
 sub cifs_cred_file_name {
     my ($storeid) = @_;
+    return "/etc/pve/priv/storage/${storeid}.pw";
+}
+
+sub cifs_delete_credentials {
+    my ($storeid) = @_;
 
-    return "/etc/pve/priv/${storeid}.cred";
+    if (my $cred_file = get_cred_file($storeid)) {
+       unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n";
+    }
 }
 
 sub cifs_set_credentials {
     my ($password, $storeid) = @_;
 
     my $cred_file = cifs_cred_file_name($storeid);
+    mkdir "/etc/pve/priv/storage";
 
     PVE::Tools::file_set_contents($cred_file, "password=$password\n");
 
@@ -49,7 +57,13 @@ sub get_cred_file {
 
     my $cred_file = cifs_cred_file_name($storeid);
 
-    return -e $cred_file ? $cred_file : undef;
+    if (-e $cred_file) {
+       return $cred_file;
+    } elsif (-e "/etc/pve/priv/${storeid}.cred") {
+       # FIXME: remove fallback with 7.0 by doing a rename on upgrade from 6.x
+       return "/etc/pve/priv/${storeid}.cred";
+    }
+    return undef;
 }
 
 sub cifs_mount {
@@ -93,7 +107,7 @@ sub properties {
            type => 'string',
        },
        password => {
-           description => "Password for CIFS share.",
+           description => "Password for accessing the share/datastore.",
            type => 'string',
            maxLength => 256,
        },
@@ -120,6 +134,7 @@ sub options {
        nodes => { optional => 1 },
        disable => { optional => 1 },
        maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        username => { optional => 1 },
@@ -145,18 +160,41 @@ sub check_config {
 sub on_add_hook {
     my ($class, $storeid, $scfg, %param) = @_;
 
-    if (my $password = $param{password}) {
-       cifs_set_credentials($password, $storeid);
+    if (defined($param{password})) {
+       cifs_set_credentials($param{password}, $storeid);
+       if (!exists($scfg->{username})) {
+           warn "ignoring password parameter\n";
+       }
+    } else {
+       cifs_delete_credentials($storeid);
+    }
+
+    return;
+}
+
+sub on_update_hook {
+    my ($class, $storeid, $scfg, %param) = @_;
+
+    return if !exists($param{password});
+
+    if (defined($param{password})) {
+       cifs_set_credentials($param{password}, $storeid);
+       if (!exists($scfg->{username})) {
+           warn "ignoring password parameter\n";
+       }
+    } else {
+       cifs_delete_credentials($storeid);
     }
+
+    return;
 }
 
 sub on_delete_hook {
     my ($class, $storeid, $scfg) = @_;
 
-    my $cred_file = cifs_cred_file_name($storeid);
-    if (-f $cred_file) {
-       unlink($cred_file) or warn "removing cifs credientials '$cred_file' failed: $!\n";
-    }
+    cifs_delete_credentials($storeid);
+
+    return;
 }
 
 sub status {
@@ -230,14 +268,12 @@ sub check_connection {
     } else {
        push @$cmd, '-U', 'Guest','-N';
     }
-
     push @$cmd, '-c', 'echo 1 0';
 
     my $out_str;
-    eval {
-       run_command($cmd, timeout => 2, outfunc => sub {$out_str .= shift;},
-                   errfunc => sub {});
-    };
+    my $out = sub { $out_str .= shift };
+
+    eval { run_command($cmd, timeout => 10, outfunc => $out, errfunc => sub {}) };
 
     if (my $err = $@) {
        die "$out_str\n" if defined($out_str) &&
@@ -248,4 +284,13 @@ sub check_connection {
     return 1;
 }
 
+sub get_volume_notes {
+    my $class = shift;
+    PVE::Storage::DirPlugin::get_volume_notes($class, @_);
+}
+sub update_volume_notes {
+    my $class = shift;
+    PVE::Storage::DirPlugin::update_volume_notes($class, @_);
+}
+
 1;