Skip to content

Commit

Permalink
Merge branch 'release-1.16.5' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed McClanahan committed Jul 13, 2020
2 parents 408df4d + cc05a27 commit 81531d9
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 840 deletions.
6 changes: 5 additions & 1 deletion conf/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,12 @@ func (confMap ConfMap) FetchOptionValueString(sectionName string, optionName str
return
}

if 0 == len(optionValueSlice) {
err = fmt.Errorf("[%v]%v must have a value", sectionName, optionName)
return
}
if 1 != len(optionValueSlice) {
err = fmt.Errorf("[%v]%v must be single-valued", sectionName, optionName)
err = fmt.Errorf("[%v]%v must have a single value", sectionName, optionName)
return
}

Expand Down
156 changes: 137 additions & 19 deletions confgen/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func computeInitial(envMap EnvMap, confFilePath string, confOverrides []string,
exportsFile *os.File
fuseSetupFile *os.File
initialConfMap conf.ConfMap
localVolumeGroupMap volumeGroupMap
localSMBVolumeGroupMap volumeGroupMap
localVolumeMap volumeMap
nfsClient *NFSClient
smbUsersSetupFile *os.File
Expand Down Expand Up @@ -181,7 +181,7 @@ func computeInitial(envMap EnvMap, confFilePath string, confOverrides []string,

// Fetch pertinent data from Initial Config

_, localVolumeGroupMap, localVolumeMap, _, _, err = fetchVolumeInfo(initialConfMap)
_, localSMBVolumeGroupMap, localVolumeMap, _, _, err = fetchVolumeInfo(initialConfMap)
if nil != err {
return
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func computeInitial(envMap EnvMap, confFilePath string, confOverrides []string,
}

// Create per VG smb.conf files
err = createSMBConf(initialDirPath, localVolumeGroupMap)
err = createSMBConf(initialDirPath, localSMBVolumeGroupMap)
if nil != err {
// TODO - logging
return
Expand Down Expand Up @@ -486,6 +486,7 @@ func computeVolumeSetChange(oldConfMap conf.ConfMap, newConfMap conf.ConfMap) (t
_, _, newLocalVolumeMap, _, _, err = fetchVolumeInfo(newConfMap)
if nil != err {
err = fmt.Errorf("In newConfMap: %v", err)
return
}

toDeleteVolumeMap = make(volumeMap)
Expand Down Expand Up @@ -518,9 +519,15 @@ func fetchStringSet(confMap conf.ConfMap, section string, value string, valueSet
)

valueAsSlice, err = confMap.FetchOptionValueStringSlice(section, value)
if (nil != err) || (0 == len(valueAsSlice)) {
if err != nil {
return
}

if 0 == len(valueAsSlice) {
data = ""
} else if 1 == len(valueAsSlice) {
return
}
if 1 == len(valueAsSlice) {
data = valueAsSlice[0]

// valueSet nil means caller is not interested in the value being unique
Expand Down Expand Up @@ -709,6 +716,7 @@ func populateVolumeGroup(confMap conf.ConfMap, globalVolumeGroupMap volumeGroupM
nfsExportClientMapSet stringSet
ok bool
shareNameSet stringSet
shared bool
tcpPort int
virtualHostNameSet stringSet
virtualIPAddrSet stringSet
Expand Down Expand Up @@ -775,25 +783,45 @@ func populateVolumeGroup(confMap conf.ConfMap, globalVolumeGroupMap volumeGroupM
return
}

// Fetch the virtual IP address for the group. It must be be a valid
// (parsable) CIDR notation IP address. Hold onto the netmask
// separtely. This code also has the effect of converting an IP address to
// canonical form (RFC-4291 or RFC-4632).
// Fetch the virtual IP address for the group. If the volume group is
// shared via NFS or SMB then it must have a virtual IP, otherwise it
// should not.
virtualIPAddr, err = fetchStringSet(confMap, volumeGroupSection, "VirtualIPAddr", virtualIPAddrSet)
if nil != err {
return
}
volumeGroup.VirtualIPAddr, volumeGroup.VirtualIPMask, err = net.ParseCIDR(virtualIPAddr)
if nil != err {
err = fmt.Errorf("ParseCIDR() for config file variable [%s][%s] value '%s' failed: %v",
volumeGroupSection, "VirtualIPAddr", virtualIPAddr, err)

shared, err = IsVolumeGroupSharedViaSMB(confMap, volumeGroupName)
if nil != err {
err = fmt.Errorf("IsVolumeGroupSharedViaSMB() failed for volume group '%s': %v",
volumeGroupName, err)
return
}
if !shared {
shared, err = IsVolumeGroupSharedViaNFS(confMap, volumeGroupName)
if nil != err {
err = fmt.Errorf("IsVolumeGroupSharedViaNFS() failed for volume group '%s': %v",
volumeGroupName, err)
return
}
}

volumeGroup.VirtualHostName, err = fetchStringSet(confMap, volumeGroupSection, "VirtualHostname", virtualHostNameSet)
if nil != err {
return
// The virtual IP must be be a valid (parsable) CIDR notation IP address.
// Hold onto the netmask separtely. This code also has the effect of
// converting an IP address to canonical form (RFC-4291 or RFC-4632).
if shared {
volumeGroup.VirtualIPAddr, volumeGroup.VirtualIPMask, err = net.ParseCIDR(virtualIPAddr)
if nil != err {
err = fmt.Errorf("ParseCIDR() for config file variable [%s][%s] value '%s' failed: %v",
volumeGroupSection, "VirtualIPAddr", virtualIPAddr, err)
return
}

volumeGroup.VirtualHostName, err = fetchStringSet(confMap, volumeGroupSection,
"VirtualHostname", virtualHostNameSet)
if nil != err {
return
}
}

// We do not check for duplicates of PrimaryPeer
Expand Down Expand Up @@ -920,10 +948,11 @@ func populateVolumeGroup(confMap conf.ConfMap, globalVolumeGroupMap volumeGroupM
return
}

func fetchVolumeInfo(confMap conf.ConfMap) (whoAmI string, localVolumeGroupMap volumeGroupMap,
func fetchVolumeInfo(confMap conf.ConfMap) (whoAmI string, localSMBVolumeGroupMap volumeGroupMap,
localVolumeMap volumeMap, globalVolumeGroupMap volumeGroupMap, globalVolumeMap volumeMap,
err error) {
var (
shared bool
volume *Volume
volumeGroup *VolumeGroup
volumeGroupList []string
Expand All @@ -943,7 +972,7 @@ func fetchVolumeInfo(confMap conf.ConfMap) (whoAmI string, localVolumeGroupMap v
return
}

localVolumeGroupMap = make(volumeGroupMap)
localSMBVolumeGroupMap = make(volumeGroupMap)
localVolumeMap = make(volumeMap)
globalVolumeMap = make(volumeMap)

Expand All @@ -954,10 +983,17 @@ func fetchVolumeInfo(confMap conf.ConfMap) (whoAmI string, localVolumeGroupMap v

for volumeGroupName, volumeGroup = range globalVolumeGroupMap {
if whoAmI == volumeGroup.PrimaryPeer {
localVolumeGroupMap[volumeGroupName] = volumeGroup
for volumeName, volume = range volumeGroup.VolumeMap {
localVolumeMap[volumeName] = volume
}

shared, err = IsVolumeGroupSharedViaSMB(confMap, volumeGroupName)
if nil != err {
return
}
if shared {
localSMBVolumeGroupMap[volumeGroupName] = volumeGroup
}
}
for volumeName, volume = range volumeGroup.VolumeMap {
globalVolumeMap[volumeName] = volume
Expand All @@ -966,3 +1002,85 @@ func fetchVolumeInfo(confMap conf.ConfMap) (whoAmI string, localVolumeGroupMap v

return
}

func IsVolumeSharedViaSMB(confMap conf.ConfMap, volumeName string) (shared bool, err error) {

volumeSection := "Volume:" + volumeName
shareName, err := fetchStringSet(confMap, volumeSection, "SMBShareName", nil)
if err != nil {
return
}

if shareName != "" {
shared = true
}
return

}

func IsVolumeSharedViaNFS(confMap conf.ConfMap, volumeName string) (shared bool, err error) {

volumeSection := "Volume:" + volumeName
clientList, err := fetchStringSet(confMap, volumeSection, "NFSExportClientMapList", nil)
if err != nil {
return
}

if clientList != "" {
shared = true
}
return

}

// IsVolumeGroupSharedViaSMB Returns true if any volume in the volume group is
// shared using SMB. While we don't support having a volume be shared by both
// SMB and NFS, it seems like two different volumes in a volume group could be,
// so a volume group might be "shared" using both protocols.
//
func IsVolumeGroupSharedViaSMB(confMap conf.ConfMap, vgName string) (shared bool, err error) {

volumeGroupSection := "VolumeGroup:" + vgName
volumeList, err := confMap.FetchOptionValueStringSlice(volumeGroupSection, "VolumeList")
if err != nil {
return
}

for _, volumeName := range volumeList {
shared, err = IsVolumeSharedViaSMB(confMap, volumeName)
if err != nil {
return
}

if shared {
return
}
}
return
}

// IsVolumeGroupSharedViaNFS Returns true if any volume in the volume group is
// shared using NFS. While we don't support having a volume be shared by both
// SMB and NFS, it seems like two different volumes in a volume group could be,
// so a volume group might be "shared" using both protocols.
//
func IsVolumeGroupSharedViaNFS(confMap conf.ConfMap, vgName string) (shared bool, err error) {

volumeGroupSection := "VolumeGroup:" + vgName
volumeList, err := confMap.FetchOptionValueStringSlice(volumeGroupSection, "VolumeList")
if err != nil {
return
}

for _, volumeName := range volumeList {
shared, err = IsVolumeSharedViaNFS(confMap, volumeName)
if err != nil {
return
}

if shared {
return
}
}
return
}
47 changes: 47 additions & 0 deletions confgen/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestConfigPath(t *testing.T) {

// Grab volumes and volume group information
_, localVolumeGroupMap, _, _, _, err := fetchVolumeInfo(confMap)
assert.Nil(err, "fetchVolumeInfo should succeed")

// Create temp directory for SMB VG configuration files
var tmpDir string
Expand All @@ -48,3 +49,49 @@ func TestConfigPath(t *testing.T) {
err = os.RemoveAll(tmpDir)
assert.Nil(err, "Remove of generated directory returned err error")
}

// Test the IsVolumeShared*() and IsVolumeGroupShared* functions.
func TestIsSharing(t *testing.T) {
assert := assert.New(t)

// Get the configuration from the config file
confMap, err := getConfMap(t, "sample-proxyfs-configuration/proxyfs.conf")
assert.Nil(err, "getConMap(sample-proxyfs-configuration/proxyfs.conf) should not fail")

var shared bool
shared, err = IsVolumeSharedViaSMB(confMap, "volume3")
assert.Nil(err, "IsVolumeSharedViaSMB(volume3) should not fail")
assert.False(shared, "volume3 is not shared via SMB")

shared, err = IsVolumeSharedViaNFS(confMap, "volume3")
assert.Nil(err, "IsVolumeSharedViaNFS(volume3) should not fail")
assert.True(shared, "volume3 is shared via NFS")

shared, err = IsVolumeSharedViaSMB(confMap, "vol-vg32-2")
assert.Nil(err, "IsVolumeSharedViaSMB(vol-vg32-2) should not fail")
assert.True(shared, "vol-vg32-2 is shared via SMB")

shared, err = IsVolumeGroupSharedViaSMB(confMap, "vg32-2")
assert.Nil(err, "IsVolumeSharedViaSMB(vg32-2) should not fail")
assert.True(shared, "vg32-2 is shared via SMB")

shared, err = IsVolumeGroupSharedViaNFS(confMap, "vg32-2")
assert.Nil(err, "IsVolumeSharedViaNFS(vg32-2) should not fail")
assert.False(shared, "vg32-2 is not shared via NFS")

shared, err = IsVolumeGroupSharedViaNFS(confMap, "VG1")
assert.Nil(err, "IsVolumeSharedViaNFS(VG1) should not fail")
assert.True(shared, "VG1 is shared via NFS")

shared, err = IsVolumeGroupSharedViaNFS(confMap, "bazbaz")
assert.NotNil(err, "volume group 'bazbaz' does not exist")

shared, err = IsVolumeSharedViaNFS(confMap, "bazbaz")
assert.NotNil(err, "volume 'bazbaz' does not exist")

shared, err = IsVolumeSharedViaSMB(confMap, "bambam")
assert.NotNil(err, "volume 'bambam' does not exist")

shared, err = IsVolumeGroupSharedViaSMB(confMap, "bambam")
assert.NotNil(err, "volume group 'bambam' does not exist")
}
Loading

0 comments on commit 81531d9

Please sign in to comment.