From 63cb1d65ca3db178cccdbfce59f4277978e990d4 Mon Sep 17 00:00:00 2001 From: nagexiucai Date: Mon, 17 Jun 2019 16:36:53 +0800 Subject: [PATCH] Remove selected IP from backup-volfile-servers list to avoid warning in mount logs. --- pkg/volume/glusterfs/glusterfs.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/volume/glusterfs/glusterfs.go b/pkg/volume/glusterfs/glusterfs.go index 9d4cb928f3d..f1fd4e64c5c 100644 --- a/pkg/volume/glusterfs/glusterfs.go +++ b/pkg/volume/glusterfs/glusterfs.go @@ -371,18 +371,26 @@ func (b *glusterfsMounter) setUpAtInternal(dir string) error { } } - //Add backup-volfile-servers and auto_unmount options. - options = append(options, "backup-volfile-servers="+dstrings.Join(addrlist[:], ":")) - options = append(options, "auto_unmount") - - mountOptions := volutil.JoinMountOptions(b.mountOptions, options) - // with `backup-volfile-servers` mount option in place, it is not required to - // iterate over all the servers in the addrlist. A mount attempt with this option - // will fetch all the servers mentioned in the backup-volfile-servers list. - // Refer to backup-volfile-servers @ http://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Clients/ - if (len(addrlist) > 0) && (addrlist[0] != "") { ip := addrlist[rand.Intn(len(addrlist))] + + // Add backup-volfile-servers and auto_unmount options. + // When ip is also in backup-volfile-servers, there will be a warning: + // "gf_remember_backup_volfile_server] 0-glusterfs: failed to set volfile server: File exists". + addr.Delete(ip) + backups := addr.List() + // Avoid an invalid empty backup-volfile-servers option. + if len(backups) > 0 { + options = append(options, "backup-volfile-servers="+dstrings.Join(addrlist[:], ":")) + } + options = append(options, "auto_unmount") + + mountOptions := volutil.JoinMountOptions(b.mountOptions, options) + // with `backup-volfile-servers` mount option in place, it is not required to + // iterate over all the servers in the addrlist. A mount attempt with this option + // will fetch all the servers mentioned in the backup-volfile-servers list. + // Refer to backup-volfile-servers @ http://docs.gluster.org/en/latest/Administrator%20Guide/Setting%20Up%20Clients/ + errs = b.mounter.Mount(ip+":"+b.path, dir, "glusterfs", mountOptions) if errs == nil { klog.Infof("successfully mounted directory %s", dir)