Skip to content

Commit 47d3bc7

Browse files
authored
NAS driver concurrency
1 parent 86cf222 commit 47d3bc7

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

core/concurrent_core.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,11 +3124,6 @@ func (o *ConcurrentTridentOrchestrator) publishVolume(ctx context.Context, volum
31243124
// Fill in what we already know
31253125
publishInfo.VolumeAccessInfo = volume.Config.AccessInfo
31263126
publishInfo.Nodes = results[0].Nodes
3127-
if err := o.reconcileNodeAccessOnBackend(ctx, backend, results[0].VolumePublications, results[0].Nodes); err != nil {
3128-
err = fmt.Errorf("unable to update node access rules on backend %s; %v", backend.Name(), err)
3129-
Logc(ctx).Error(err)
3130-
return err
3131-
}
31323127

31333128
if err := backend.PublishVolume(ctx, volume.Config, publishInfo); err != nil {
31343129
return err
@@ -5043,6 +5038,10 @@ func (o *ConcurrentTridentOrchestrator) DeleteNode(ctx context.Context, nodeName
50435038
return fmt.Errorf("failed to delete node %s in store: %v", nodeName, err)
50445039
}
50455040
deleteNode()
5041+
5042+
// TODO: enable this with periodic node reconciliation
5043+
// o.invalidateAllBackendNodeAccess(ctx)
5044+
50465045
return
50475046
}
50485047

core/concurrent_core_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10663,7 +10663,6 @@ func TestPublishVolumeConcurrentCore(t *testing.T) {
1066310663
driver.EXPECT().GetStorageBackendSpecs(gomock.Any(), gomock.Any()).Return(nil)
1066410664
driver.EXPECT().CreateFollowup(gomock.Any(), gomock.Any()).Return(nil)
1066510665
driver.EXPECT().Publish(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
10666-
driver.EXPECT().ReconcileNodeAccess(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
1066710666

1066810667
fakeNode := getFakeNode("testNode")
1066910668
addNodesToCache(t, fakeNode)

storage_drivers/ontap/api/ontap_rest.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,26 @@ func (c *RestClient) ClientConfig() ClientConfig {
7777
}
7878

7979
func (c *RestClient) SetSVMUUID(svmUUID string) {
80+
c.m.Lock()
81+
defer c.m.Unlock()
8082
c.svmUUID = svmUUID
8183
}
8284

8385
func (c *RestClient) SVMUUID() string {
86+
c.m.RLock()
87+
defer c.m.RUnlock()
8488
return c.svmUUID
8589
}
8690

8791
func (c *RestClient) SetSVMName(svmName string) {
92+
c.m.Lock()
93+
defer c.m.Unlock()
8894
c.svmName = svmName
8995
}
9096

9197
func (c *RestClient) SVMName() string {
98+
c.m.RLock()
99+
defer c.m.RUnlock()
92100
return c.svmName
93101
}
94102

storage_drivers/ontap/ontap_common.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ var (
154154
smbShareDeleteACL = map[string]string{DefaultSMBAccessControlUser: DefaultSMBAccessControlUserType}
155155
lunMutex = locks.NewGCNamedMutex()
156156
igroupMutex = locks.NewGCNamedMutex()
157+
exportPolicyMutex = locks.NewGCNamedMutex()
157158

158159
duringVolCloneAfterSnapCreation1 = fiji.Register("duringVolCloneAfterSnapCreation1", "ontap_common")
159160
duringVolCloneAfterSnapCreation2 = fiji.Register("duringVolCloneAfterSnapCreation2", "ontap_common")
@@ -305,9 +306,19 @@ func InitializeOntapConfig(
305306
}
306307

307308
func ensureExportPolicyExists(ctx context.Context, policyName string, clientAPI api.OntapAPI) error {
309+
exportPolicyMutex.Lock(policyName)
310+
defer exportPolicyMutex.Unlock(policyName)
311+
308312
return clientAPI.ExportPolicyCreate(ctx, policyName)
309313
}
310314

315+
func destroyExportPolicy(ctx context.Context, policyName string, clientAPI api.OntapAPI) error {
316+
exportPolicyMutex.Lock(policyName)
317+
defer exportPolicyMutex.Unlock(policyName)
318+
319+
return clientAPI.ExportPolicyDestroy(ctx, policyName)
320+
}
321+
311322
func getExportPolicyName(backendUUID string) string {
312323
return fmt.Sprintf("trident-%s", backendUUID)
313324
}
@@ -380,12 +391,15 @@ func ensureNodeAccessForPolicy(
380391
Logc(ctx).WithFields(fields).Debug(">>>> ensureNodeAccessForPolicy")
381392
defer Logc(ctx).WithFields(fields).Debug("<<<< ensureNodeAccessForPolicy")
382393

394+
exportPolicyMutex.Lock(policyName)
395+
defer exportPolicyMutex.Unlock(policyName)
396+
383397
if exists, err := clientAPI.ExportPolicyExists(ctx, policyName); err != nil {
384398
return err
385399
} else if !exists {
386400
Logc(ctx).WithField("exportPolicy", policyName).Debug("Export policy missing, will create it.")
387401

388-
if err = ensureExportPolicyExists(ctx, policyName, clientAPI); err != nil {
402+
if err = clientAPI.ExportPolicyCreate(ctx, policyName); err != nil {
389403
return err
390404
}
391405
}
@@ -496,6 +510,9 @@ func reconcileExportPolicyRules(
496510
Logc(ctx).WithFields(fields).Debug(">>>> reconcileExportPolicyRules")
497511
defer Logc(ctx).WithFields(fields).Debug("<<<< reconcileExportPolicyRules")
498512

513+
exportPolicyMutex.Lock(policyName)
514+
defer exportPolicyMutex.Unlock(policyName)
515+
499516
// first grab all existing rules
500517
existingRules, err := clientAPI.ExportRuleList(ctx, policyName)
501518
if err != nil {
@@ -4904,6 +4921,9 @@ func removeExportPolicyRules(
49044921
Logc(ctx).WithFields(fields).Debug(">>>> removeExportPolicyRules")
49054922
defer Logc(ctx).WithFields(fields).Debug("<<<< removeExportPolicyRules")
49064923

4924+
exportPolicyMutex.Lock(exportPolicy)
4925+
defer exportPolicyMutex.Unlock(exportPolicy)
4926+
49074927
var removeRuleIndexes []int
49084928

49094929
nodeIPRules := make(map[string]struct{})

storage_drivers/ontap/ontap_nas.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ type NASStorageDriver struct {
6262
}
6363

6464
func (d *NASStorageDriver) GetConfig() drivers.DriverConfig {
65-
return &d.Config
65+
return d.Config.SmartCopy()
6666
}
6767

6868
func (d *NASStorageDriver) GetOntapConfig() *drivers.OntapStorageDriverConfig {
69-
return &d.Config
69+
return d.Config.SmartCopy()
7070
}
7171

7272
func (d *NASStorageDriver) GetAPI() api.OntapAPI {
@@ -185,7 +185,7 @@ func (d *NASStorageDriver) Terminate(ctx context.Context, backendUUID string) {
185185
if d.Config.AutoExportPolicy {
186186
policyName := getExportPolicyName(backendUUID)
187187

188-
if err := d.API.ExportPolicyDestroy(ctx, policyName); err != nil {
188+
if err := destroyExportPolicy(ctx, policyName, d.API); err != nil {
189189
Logc(ctx).Warn(err)
190190
}
191191
}
@@ -965,8 +965,9 @@ func (d *NASStorageDriver) Unpublish(
965965
volConfig.ExportPolicy = getEmptyExportPolicyName(*d.Config.StoragePrefix)
966966

967967
// Remove export policy if no rules exist
968-
if err = d.API.ExportPolicyDestroy(ctx, exportPolicy); err != nil {
969-
Logc(ctx).WithError(err).Errorf("Error deleting export policy %s.", exportPolicy)
968+
if err = destroyExportPolicy(ctx, exportPolicy, d.API); err != nil {
969+
Logc(ctx).WithError(err).Errorf("Could not delete export policy %s.", exportPolicy)
970+
return err
970971
}
971972
}
972973

@@ -986,6 +987,7 @@ func (d *NASStorageDriver) Unpublish(
986987
// setVolToEmptyPolicy set export policy to the empty policy.
987988
func (d *NASStorageDriver) setVolToEmptyPolicy(ctx context.Context, volName string) error {
988989
emptyExportPolicy := getEmptyExportPolicyName(*d.Config.StoragePrefix)
990+
989991
exists, err := d.API.ExportPolicyExists(ctx, emptyExportPolicy)
990992
if err != nil {
991993
return err
@@ -1713,6 +1715,7 @@ func (d *NASStorageDriver) reconcileNodeAccessForBackendPolicy(
17131715
Logc(ctx).Error(err)
17141716
return err
17151717
}
1718+
17161719
err = reconcileExportPolicyRules(ctx, policyName, desiredRules, d.API, &d.Config)
17171720
if err != nil {
17181721
err = fmt.Errorf("unabled to reconcile export policy rules; %v", err)

0 commit comments

Comments
 (0)