Skip to content

Added the --nfs flag missing check while download from Azure Files NFS #3022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dphulkar/NFSOverRESTSupport
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions cmd/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,11 +1557,20 @@ func (cca *CookedCopyCmdArgs) processCopyJobPartOrders() (err error) {
}
}

if err := validateProtocolCompatibility(ctx, cca.FromTo,
cca.Destination,
jobPartOrder.DstServiceClient,
cca.isNFSCopy); err != nil {
return err
if (cca.FromTo.IsUpload() || cca.FromTo.IsS2S()) && cca.FromTo.To() == common.ELocation.File() {
if err := validateProtocolCompatibility(ctx, cca.FromTo,
cca.Destination,
jobPartOrder.DstServiceClient,
cca.isNFSCopy); err != nil {
return err
}
} else if cca.FromTo.IsDownload() && cca.FromTo.From() == common.ELocation.File() {
if err := validateProtocolCompatibility(ctx, cca.FromTo,
cca.Source,
jobPartOrder.SrcServiceClient,
cca.isNFSCopy); err != nil {
return err
}
}

switch {
Expand Down
35 changes: 20 additions & 15 deletions cmd/flagsValidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,49 +101,54 @@ func areBothLocationsSMBAware(fromTo common.FromTo) bool {
}
}

// validateProtocolCompatibility checks if the destination share protocol (SMB or NFS) is compatible with the --nfs flag
// with the type of copy operation (NFS or SMB) requested. It returns an error if there is a protocol mismatch with the --nfs flag.
// validateProtocolCompatibility checks whether the target Azure Files share
// supports the correct protocol (NFS or SMB) based on the transfer direction
// and the presence of the --nfs flag. It attempts to fetch the share's properties,
// and falls back to an assumption (with an info message) if the check fails.
func validateProtocolCompatibility(ctx context.Context,
fromTo common.FromTo,
destination common.ResourceString,
dstServiceClient *common.ServiceClient,
resource common.ResourceString,
serviceClient *common.ServiceClient,
isNFSCopy bool) error {

if fromTo.To() != common.ELocation.File() {
return nil
}

fileURLParts, err := file.ParseURL(destination.Value)
fileURLParts, err := file.ParseURL(resource.Value)
if err != nil {
return err
}
shareName := fileURLParts.ShareName
fileServiceClient, err := dstServiceClient.FileServiceClient()

fileServiceClient, err := serviceClient.FileServiceClient()
if err != nil {
return err
}

direction := "to"
if fromTo.IsDownload() {
direction = "from"
}

shareClient := fileServiceClient.NewShareClient(shareName)
properties, err := shareClient.GetProperties(ctx, nil)
if err != nil {
if isNFSCopy {
glcm.Info("Failed to fetch share properties. Assuming the transfer to Azure Files NFS share")
glcm.Info(fmt.Sprintf("Failed to fetch share properties. Assuming the transfer %s Azure Files NFS", direction))
} else {
glcm.Info("Failed to fetch share properties. Assuming the transfer to Azure Files SMB share")
glcm.Info(fmt.Sprintf("Failed to fetch share properties. Assuming the transfer %s Azure Files SMB", direction))
}
return nil
}

// for older account the EnablesProtocols will be nil
// For older accounts, EnabledProtocols may be nil
if properties.EnabledProtocols == nil || *properties.EnabledProtocols == "SMB" {
if isNFSCopy {
return errors.New("the destination share has SMB protocol enabled. If you want to perform copy for SMB share do not use --nfs flag")
return fmt.Errorf("The %s share has SMB protocol enabled. If you want to perform a copy %s an SMB share, do not use the --nfs flag", shareName, direction)
}
} else {
if !isNFSCopy {
return errors.New("the destination share has NFS protocol enabled. If you want to perform copy for NFS share please provide --nfs flag")
return fmt.Errorf("The %s share has NFS protocol enabled. If you want to perform a copy %s an NFS share, please provide the --nfs flag", shareName, direction)
}
}

return nil
}

Expand Down
20 changes: 14 additions & 6 deletions cmd/syncEnumerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,20 @@ func (cca *cookedSyncCmdArgs) initEnumerator(ctx context.Context) (enumerator *s
azureFileSpecificOptions,
)

// we will do the protocol compatibility check after the destination service client is created.
if err := validateProtocolCompatibility(ctx, cca.fromTo,
cca.destination,
copyJobTemplate.DstServiceClient,
cca.isNFSCopy); err != nil {
return nil, err
if (cca.fromTo.IsUpload() || cca.fromTo.IsS2S()) && cca.fromTo.To() == common.ELocation.File() {
if err := validateProtocolCompatibility(ctx, cca.fromTo,
cca.destination,
copyJobTemplate.DstServiceClient,
cca.isNFSCopy); err != nil {
return nil, err
}
} else if cca.fromTo.IsDownload() && cca.fromTo.From() == common.ELocation.File() {
if err := validateProtocolCompatibility(ctx, cca.fromTo,
cca.source,
copyJobTemplate.SrcServiceClient,
cca.isNFSCopy); err != nil {
return nil, err
}
}

transferScheduler := newSyncTransferProcessor(cca, NumOfFilesPerDispatchJobPart, fpo, copyJobTemplate)
Expand Down
Loading