This topic provides answers to some frequently asked questions (FAQ) about how to mount an Apsara File Storage NAS file system.

How can I create and mount a subdirectory of a NAS file system on Linux?

Make sure that a file system is mounted. For more information, see Mount an NFS file system.

If you mount the /mnt directory of the file system on the server, the /mnt directory serves as the root directory of the file system. You can create subdirectories in the /mnt directory.

  1. Create a subdirectory under the root directory of the NAS file system on the server, for example, an ECS Linux instance.
    mkdir /mnt/subdir
  2. Create a local directory on which you can mount the NAS file system.
    mkdir /tmp/mnt
    Note After you create a local directory on a server, you can mount only one file system on the local directory. To mount multiple file systems, you must create multiple local directories.
  3. Remount the file system.
    sudo mount -t nfs -o vers=4,minorversion=0,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport file-system-id.region.nas.aliyuncs.com:/subdir /tmp/mnt
    The following list describes the required fields. Replace these fields with values that are specific to your environment.
    • file-system-id.region.nas.aliyuncs.com: specifies the endpoint of the mount target. To retrieve the endpoint of the mount target, perform the following steps: Log on to the NAS console, find the required file system, and then click Manage. You can find the endpoint of the mount target on the page that appears.
    • /subdir: specifies the subdirectory of the NAS file system.
    • /tmp/mnt: specifies the local directory of the server.

How can I fix issues that occur on an ECS Linux instance when I delete a mount target by mistake?

  • Problem description

    A file system is mounted on an ECS Linux instance through Mount target A. However, the mount target is deleted by mistake from the NAS console before the file system is unmounted. In this case, issues occur on Linux. For example, the system freezes and no response is returned when you execute commands.

  • Solution
    1. On the ECS Linux instance, press Ctrl+C to stop command execution.
    2. Run the mount command to view the mount information.
      Obtain the mount target from the mount information, for example, /mnt/data. View mount information
    3. Run the umount -f /mnt/data command to unmount the file system.
      Command syntax: unmount-f <Mount point>
      Note If the unmount -f <Mount point> command fails to unmount the file system, run the umount -l <Mount point> command.
      After you unmount the file system, you can create a mount target to mount the file system.

How can I prevent an NFS 4.0 listening port from being mistaken for a Trojan horse?

  • Problem description

    After you mount an NFS 4.0 file system on a client, the system of the instance listens to a random listening port of 0.0.0.0. The system cannot run the netstat command to locate the process of the listening port.

    The listening port is random and the backend application of the listening port cannot be traced. In this case, the listening port is often mistaken for a trojan horse.

  • Cause

    NFS 4.0 listens to this random port to correspond to callback operations. By default, the fs.nfs.nfs_callback_tcpport kernel parameter is set to 0. Therefore, an NFS 4.0 client listens to a random port. This random port does not incur a security risk.

    To facilitate port management, you can use the following method to specify the required value for the callback port.

  • Solution
    Before you mount a file system, you can specify a non-zero value for the fs.nfs.nfs_callback_tcpport parameter. The non-zero value is used as the number of the callback port.
    sudo sysctl fs.nfs.nfs_callback_tcpport=<port>          

    In the following example, the fs.nfs.nfs_callback_tcpport parameter is set to 45450. After you mount an NFS 4.0 file system, the result that is returned by the netstat command indicates that the system listens to port 45450. Note: The root user is used in the following figure. Therefore, you do not need to use sudo to run the sysctl command.

How can I troubleshoot and fix an error that occurs when I mount an SMB file system on Windows?

  1. System error 53
    • Error message

      The network path is not found.

    • Cause
      • The network connection fails.
      • The TCP/IP NetBIOS Helper service is disabled.
      • LanmanWorkstation is not set in the registry.
    • Solution

      Perform the following steps to troubleshoot the error:

      1. Run the following ping command to check whether the IP address of a mount target is accessible and whether the latency is within the normal range:

        ping <IP address of a mount target>

        • If you can ping the IP address of the mount target, go to Step 2.
        • Otherwise, perform the following steps:
          • Make sure that the mount command is valid. For example, the command neither includes redundant forward slashes (/), backslashes (\), spaces, or myshare nor misses any of these when necessary.
            To run a valid command to mount an SMB file system, use the following syntax:
            net use <Letter of the destination drive> \\<Domain name of a mount target>\myshare
            Example:
            net use z: \\xxxx.cn-hangzhou.nas.aliyuncs.com\myshare 
          • Make sure that the protocol type of the file system is SMB.
          • Make sure that the domain name of the mount target is valid.
          • Make sure that the Elastic Compute Service (ECS) instance and the mount target reside in the same virtual private cloud (VPC).
          • If the ECS instance and the mount target do not reside in the same VPC, make sure that the VPC or virtual private network (VPN) configurations of the ECS instance are valid.
      2. Run the following telnet command to check whether the SMB protocol is enabled:

        telnet <Domain name of a mount target> 445

      3. Check whether the TCP/IP NetBIOS Helper service is started. For more information, see Mount an SMB file system on Windows.
      4. Check the Windows registry.

        Open the Registry Editor, choose HKEY_LOCAL_MACHINE > System > CurrentControlSet > Control > NetworkProvider > Order. In the dialog box that appears, check whether the ProviderOrder key contains the LanmanWorkstation value. If not, add the value to the ProviderOrder key.

  2. System error 58
    • Error message

      The specified server cannot perform the requested operation.

    • Cause

      The Windows operating system that the ECS instance runs is incompatible with the SMB protocol that is used for the file system.

    • Solution

      Make sure that the ECS instance runs Windows Server 2008 R2 or later (excluding Windows Server 2008).

  3. System error 64
    • Error message

      The specified network name is no longer available.

    • Cause
      • The IP address of the ECS instance is excluded from the permission groups of the NAS file system.
      • The internal IP address or VPC IP address of the ECS instance is not properly configured in NAS permission groups.
      • Your payment for Alibaba Cloud services is overdue.
      • The ECS instance and the NAS file system reside in the classic network. However, the ECS instance and the NAS file system belong to different Alibaba Cloud accounts.
      • The protocol type of the file system is not SMB.
    • Solution
      This error occurs when the NAS file system is not accessible. Perform the following steps to troubleshoot the error:
      1. Make sure that the private IP address or VPC IP address of the ECS instance is included in the permission groups of the NAS file system.
      2. Make sure that your Alibaba Cloud account is not in arrears.
      3. Make sure that you create the ECS instance and the NAS file system within the same Alibaba Cloud account if they reside in the classic network.
      4. Make sure that the protocol type of the file system is SMB. System error 64
  4. System error 67
    • Error message

      The network name cannot be found.

    • Cause

      Key network services are not started.

    • Solution
      Start the following services. For more information, see Mount an SMB file system on Windows.
      1. Enable the Workstation service.
      2. The TCP/IP NetBIOS Helper service.
  5. System error 85
    • Error message

      The local device name is already in use.

    • Cause

      The drive letter is already being used.

    • Solution

      Change the drive letter and remount the file system.

  6. System error 1231
    • Error message

      The network location is unavailable.

    • Cause
      • The Client for Microsoft Networks component is not installed or enabled.
      • The File and Printer Sharing for Microsoft Networks component is not installed or enabled.
    • Solution

      Install and enable the Client for Microsoft Networks or File and Printer Sharing for Microsoft Networks component.

      If the Client for Microsoft Networks or File and Printer Sharing for Microsoft Networks component is installed but not enabled, select the related options.

      Perform the following steps to install and enable the component:

      1. On the Network and Sharing Center page, click the active network connection.
      2. Click Properties.
      3. In the WLAN Properties dialog box, click Install.
        • Install the Client for Microsoft Networks component.
          1. In the Select Network Feature Type dialog box, select Client, and click Add.
          2. Select Client for Microsoft Networks and click OK.
        • Install the File and Printer Sharing for Microsoft Networks component.
          1. In the Select Network Feature Type dialog box, select Service, and click Add.
          2. Choose Microsoft > File and Printer Sharing for Microsoft and click OK.
  7. System error 1272
    • Error message

      Error message: You cannot access this shared folder because your organization's security policies block unauthenticated guest access. These policies protect your PC from unsafe or malicious devices on the network.

    • Cause

      The security policies of the Windows operating system do not allow guest users to access the SMB file system.

    • Solution
      If the ECS instance runs a Windows operating system later than Windows Server 2016 (excluding Windows Server 2016), modify the following registry to allow access from guest users:
      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
      "AllowInsecureGuestAuth"=dword:1
      For more information, see Guest access in SMB 2 disabled by default in Windows.

Why do two ECS instances have different owners of files when I query the same file in a NAS file system?

In NAS file systems, users are identified by User Identifiers (UIDs) or Group Identifiers (GIDs) rather than by user names. The owner name you query on the ECS instance is converted from UID. If an UID is converted into different user names on different ECS instances, the UID is considered as belonging to different owners.

For example, use the admin user to create a file admin_on_machine1 on ECS instance 1 and use the admin user to create a file admin_on_machine2on ECS instance 2. Run the ls -l command on ECS instance 1 to view the created file in the following picture.faq001Run the ls -l command on ECS instance 2 to view the created file in the following picture.faq002The query results on two ECS instances show that the owner usernames of the same file are different.
Then, run the id command on two ECS instances to query the admin user. The following figure shows that the UID of the admin user on ECS instance 1 is 505:faq04The following figure shows that the UID of the admin user on ECS instance 2 is 2915:faq005Run the stat admin_on_machine1 admin_on_machine2 command in the following figure. Then, you can find that the two files belong to users of two UIDs:faq

Why am I unable to mount an SMB file system on a Windows system that is later than Windows Server 2016?

  • Problem description

    An error occurred when the following command was running.

    C:\Users\Administrator>net use z: \\xxxxx-xxxx.xxxxx.nas.aliyuncs.com\myshare
    System error 1272 has occurred.
    You can't access this shared folder because your organization's security policies block unauthenticated guest access. These policies help protect your PC from unsafe or malicious devices on the network.
  • Solution

    This error occurs because the security policies of a Windows system that is later than Windows Server 2016 do not allow guest users to access remote shared directories.

    Perform the following steps to fix the error:

    • Locate the following registry key.
      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
      "AllowInsecureGuestAuth"=dword:0

      Modify the key.

      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters]
      "AllowInsecureGuestAuth"=dword:1
    • Switch to Powershell and run the following command:
      New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType DWORD -Force

    For more information, see Guest access in SMB2 disabled by default in Windows 10, Windows Server 2016 version 1709, and Windows Server 2019.

Why do I sometimes fail to mount an SMB file system?

  • Problem description

    The net use command is used to mount SMB file systems. However, the command may be mistakenly used to mount NFS file systems. If you make this mistake, then you are unable to mount the SMB file system.

  • Solution

    Make sure that the protocol of the file system is SMB. Then, stop mounting the file system and try again after 5 minutes. If the issue still exists,.

Why is a mounted SMB directory available only to an administrator?

This issue occurs because Windows user accounts are isolated from each other.

To enable access from multiple users, create a shared directory. For example, you can run the following command to create a shared directory named myshare on C drive:
mklink /D C:\myshare \\xxxxxxx-xxxx.cn-beijing.nas.aliyuncs.com\myshare\

Why is Internet Information Services (IIS) unable to load the files of a SMB volume on Windows Server 2016?

If this issue occurs, see Install and configure Active Directory domains.

How can I troubleshoot and fix an error when I use IIS to access a NAS file system?

An HTTP error 500.19 with error code 0x8007003a occurs when you mount an SMB file system on Windows Server 2016. For more information about how to fix this error, see Best practices for using IIS to access a NAS file system.

Can I mount an NFS file system and SMB file system on the same ECS instance?

No, you cannot mount an NFS file system and SMB file system on the same ECS instance.

We recommend that you do not access an SMB file system by using a Linux client due to compatibility issues. For example, the supported character sets and the length of a file name for Windows and Linux are different. In Windows, a maximum length of 255 wide characters encoded with Unicode is supported. While in Linux, a maximum length of 255 characters encoded with UTF-8 is supported.

If you need to mount an NFS file system and an SMB file system on the same ECS instance, you can mount an SMB file system on an ECS Linux instance whose kernel supports SMB 2 or later.

Run either one of the following mount commands: mount -t cifs -o vers=2.0 \\<A mount target>\myshare /mnt or mount -t cifs -o vers=2.0 //<A mount target>/myshare /mnt. If a password is required, press Enter.

To check whether your Linux kernel supports the CIFS protocol, view the value of CONFIG_CIFS in the /boot directory. A value of y or m indicates that the protocol is supported and a CIFS file system can be mounted.

Note
  • Before you run the preceding command, you must install the cifs-utils tool. Run the following command to install the cifs-utils tool on CentOS:
    yum install samba-client samba-common cifs-utils
  • If the CIFS protocol is not supported on the current version of Linux, we recommend that you upgrade the Linux kernel to version 3.10.0-514 or later.

Why am I unable to mount an SMB file system on Linux?

Cause:
  • You are using an earlier or incompatible version of a Linux distribution. SMB file systems support the following Linux distributions:
    • CentOS 7.6 64-bit (3.10.0-957.5.1.el7.x86_64)
    • Ubuntu 18.04 64-bit (4.15.0-48-generic)
    • Debian 9.9 64-bit (4.9.0-9-amd64)
    • SUSE Enterprise Server 12 SP2 64-bit (4.4.74-92.35-default)
    • openSUSE 42.3 64-bit (4.4.90-28-default)
    • Aliyun Linux (4.19.34-11.al7.x86_64)
    • CoreOS (4.19.43-coreos VersionID=2079.4.0)
  • The cifs-utils tool is not installed on the client, or the executable file of the mount.cifs command is not in a directory that is specified by the PATH environment variable.
  • No network connection is established between the ECS Linux instance and the SMB file system.
    • The ECS Linux instance and the SMB file system belong to different Alibaba Cloud accounts.
    • The ECS Linux instance and the SMB file system reside in different regions.
    • The ECS Linux instance and the SMB file system reside in different networks. For example, the ECS Linux instance and the SMB file system reside in different virtual private clouds (VPCs) or one of them resides in a VPC and the other resides in the classic network.
      Note You can mount a NAS file system on an on-premises Linux server. If you cannot access the file system from the Linux server, a probable cause is that no network connection is established between the Linux server and the file system. To establish a network connection, use Express Connect.
    • The IP address of the ECS Linux instance is excluded from the permission groups of the SMB file system.
    • The firewall of the ECS Linux instance denies access to the IP address or port 445 of the SMB file system.
    • The ECS Linux instance attempts to connect to the SMB file system by using an unsupported Transmission Control Protocol (TCP) port. SMB file systems support only port 445.
    Note

    You can run the ping <VolumeDomainName> and telnet <VolumeDomainName>445 commands to check the network connectivity.

    If port 445 is disabled, you must add rules for port 445 to a security group of the ECS instance. For more information, see Add security group rules.

  • The account that you use to log on to the ECS Linux instance does not have the root permissions or is not authorized to run the mount command. You can run the sudo command to authorize the account to run the mount command.
  • The file system type is not set to Common Internet File System (CIFS) when you mount the file system.
  • The value of the vers option in the mount command is not 2.0.
  • The guest option is not set to username=guest, password=guest, or guest.
  • The specified value for uid, gid, dir_mode, or file_mode is invalid.
  • The Security-Enhanced Linux (SELinux) settings for the mount directory are invalid.
  • The file system is mounted on more than 1,000 ECS Linux instances. This issue often occurs when you mount a file system on containers.
Solution
  1. Troubleshoot the failure based on the preceding causes. For more information, see Mount an SMB file system on a Linux ECS instance.
  2. Troubleshoot the failure based on the /var/log/messages file and the output of the dmesg command.
  3. Submit a and contact Alibaba Cloud Technical Support for further assistance.

    When you submit a ticket, you must provide the version of your Linux distribution, mount commands, /var/log/messages file, and output of the dmesg command.

How can I improve the performance of an SMB file system that is mounted on Linux?

You can improve the performance of the SMB file system based on the following potential causes:

  • Cause 1: The maximum read/write throughput of the SMB file system has a linear relationship with the capacity of the file system.

    Solution: Use the fio tool to test the performance of the SMB file system. For more information, see Performance testing for Apsara File Storage NAS.

  • Cause 2: The bandwidth of the ECS Linux instance is low.

    Solution: Use multiple ECS instances to achieve the expected performance of the file system.

  • Cause 3: Caching is disabled for the SMB client.

    Solution: If the cache option is set to strict, caching is enabled. If the cache option is set to none, caching is disabled. By default, caching for an SMB client is enabled. You can run the sudo mount | grep cifs command to check the value of the cache option.

  • Cause 4: The I/O size of the SMB client does not meet your business requirements.

    Solution: Specify the rsize and wsize options based on your business requirements. The default value of the two options is 1048576.

  • Cause 5: The ECS Linux instance uses low-specification CPU or memory, or most CPU or memory resources are occupied by other processes.

    Solution: Specify the required specifications for the ECS Linux instance. Check the usage of CPU and memory resources. This ensures that the file system is functioning as expected. You can run the top command to check the usage of CPU and memory resources.

  • Cause 6: The atime option is specified when you mount the file system.

    Solution: Do not specify the atime option if your business is insensitive to the file access time.

  • Cause 7: The web server such as Apache HTTP Server on the ECS Linux instance processes a few write requests. These requests require notifications and frequent read operations on a large number of small files.

    Solution: Configure the caching mechanism of the web server on the ECS Linux instance. You can also contact Alibaba Cloud to enable the acceleration feature for the web server.

Why is the speed of file migration and replication slow when I mount an SMB file system on Linux?

Troubleshoot the performance issue based on the preceding list of causes. If the issue persists, the probable cause is that concurrent migration or replication is disabled. You can use the following open source tools to migrate or replicate files.

  • GNU Parallel

    Specify an appropriate number of threads based on your system resources. Example: find * -type | parallel --will-cite -j 10 cp {} /mnt/smb/ &

  • Fpart
  • Fpsync
  • multi

How can I fix the "Permission denied" error when I access an SMB file system on Linux?

Cause: You have specified an invalid value for the uid, gid, file_mode, or dir_mode parameter when you mount the file system.

Solution: Check whether the values that are specified for the uid, gid, file_mode, and dir_mode options are valid. For more information, see Mount an SMB file system on a Linux ECS instance.

How can I rename the files of an SMB file by changing the letter case?

The file names of an SMB file system are case-insensitive. This also applies to Windows systems. A file in an SMB file system cannot be renamed by changing only the letter case.

However, you can change a file name to another name that includes different letters. Then, you can change the file name back to the original name, and user a different letter case.

Why am I unable to change the owner of a file and access mode of a file or directory?

You can specify the owner of a file and access mode of a file or directory in a file system only when you mount the file system. For more information, see Mount an SMB file system on a Linux ECS instance.

Why does the server not respond within 35 seconds when multiple clients concurrently access a file?

Cause: The Linux SMB kernel driver is defective. If the SMB protocol version is 2.1 or 3.0, the server does not respond within 35 seconds. In this case, the clients cannot send SMB break acknowledgment packets to the server.

Solution 1: Set vers to 2.0 when you mount the file system on the ECS Linux instance.

Solution 2: Perform the following operations:
  1. Run the following command to disable the oplock feature when the system loads the CIFS module:

    # modprobe cifs enable_oplocks=0

  2. Run the following command to disable the oplock feature when the CIFS module is loaded:

    # echo 0 > /sys/module/cifs/parameters/enable_oplocks

  3. Run the following command to check the status of the oplock feature:

    # cat /sys/module/cifs/parameters/enable_oplocks

    In the result, Y indicates that the feature is enabled. N indicates that the feature is disabled.

    Note
    • To apply the preceding changes, unmount and remount the SMB file system.
    • To keep the preceding changes applied for an extended period of time, create the /etc/modprobe.d/cifs.conf file and add the options cifs enable_oplocks=0 statement to the file.

Why does the mount target of an SMB file system become unresponsive?

Cause: If the kernel version of your Linux distribution is 3.10.0-514 or earlier, the SMB kernel driver may stop responding when multiple clients concurrently access a file system. In this case, access to the file system fails. The following example shows log entries that record the failure in the kernel log file:
...
[<ffffffffc03c9bc1>] cifs_oplock_break+0x1f1/0x270 [cifs]
[<ffffffff810a881a>] process_one_work+0x17a/0x440
[<ffffffff810a8d74>] rescuer_thread+0x294/0x3c0
...
Solution
  • Set cache to none when you remount the file system. This may affect the performance of the file system.
  • Upgrade the operating system of the ECS Linux instance.

How can I fix an error that occurs when I mount an NFS file system on Windows?

  • Error message: Invalid file handler

    Solution: Perform valid steps and set the required parameters to remount the file system. For more information, see Mount an NFS file system on an ECS Windows instance.

  • Error message: Network error 53

    Solution: Perform valid steps and set the required parameters to remount the file system. For more information, see Mounting NFS on a Windows Client.

  • Error message: Network error 1222

    Solution: After you install an NFS client, remount the file system. For more information, see Install the NFS client.

How can I troubleshoot and fix issues about soft mounts of an NFS file system on Windows?

  • Error
    When you mount an NFS file system on Windows, the soft mode is used by default. However, in some scenarios, soft mounts result in data inconsistency or unexpected application exits. Possible issues:
    • Data inconsistency: An application sends an ECS instance a request to write data to a soft-mounted file system. If the application does not receive a response from the instance before the request times out, an error is returned even if data is written to the file system. This causes data inconsistency. Data inconsistency may occur when the application does not receive a response from the server, but the ECS instance may have responded to the request.
    • Unexpected application exits: An application sends an ECS instance a request to access a soft-mounted file system. If the application does not receive a response from the instance before the request times out, an error is returned. In this case, if the application is written in a specific programming language, an exception is thrown. If the exception is not handled, the application exits.
  • Solution 2
    To prevent these issues, hard mount the NFS file system on the ECS Windows instance.
    1. Run the mount command to view the mount mode.
      • If the command output includes mount=soft, perform the following steps.
      • If the command output includes mount=hard, you do not need to perform the following steps.
    2. Stop the application that is using the NFS file system.
    3. Run the following command to unmount the NFS file system:
      umount H:
      Replace the drive letter H: based on your business requirements.
    4. Run the following command to remount the NFS file system:
      mount -o nolock -o mtype=hard -o timeout=60 \\xxxxxx.cn-hangzhou.nas.aliyuncs.com\! h:
      Replace the mount target address xxxxxx.cn-hangzhou.nas.aliyuncs.com and the drive letter h: based on your business requirements.
    5. Run the mount command to verify the mount result:
      The mount is successful if the command output includes mount=hard, locking=no, and timeout=10 (or a number greater than 10).

How can I prevent exceptions when multiple processes or clients concurrently write data to a log file?

  • Problem description

    Apsara File Storage NAS allows multiple clients to share and write files in the same namespace over NFS. However, NFS does not support atomic appends. In this case, some exceptions may occur. This applies when multiple processes or clients concurrently write data to the same file (such as a log), and each process independently maintains context information (such as file descriptors and write locations). These exceptions include overwrite, crossover, and disordered content.

  • Solutions
    • Recommended. Different processes or clients write data to different files in the same file system. When you analyze or process data in the future, you can consolidate these files. This can effectively fix issues that are caused by concurrent writes without the need to use file locks. In addition, the solution will not affect system performance.
    • Use a combination of the flock and seek functions. This ensures the atomicity and consistency of writes. However, this solution is time-consuming and may significantly affect system performance. The following steps are provided as an introduction to this method.
  • Use a combination of the flock and seek functions

    NFS does not support atomic appends. If multiple clients append data to the same file such as a log, overwrite issues may occur. In Linux, you can use a combination of the flock and seek functions to simulate atomic appends on an NFS file system. This ensures data consistency when multiple processes concurrently append data to the same file.

    Perform the following steps:
    1. Execute the fd=open(filename, O_WRONLY | O_APPEND | O_DIRECT) statement to open a file by using the append method. This statement is used to set the write method to O_DIRECT and obtain the file descriptor. O_DIRECT specifies a write-only method. In this case, no page cache is used.
    2. Call the flock(fd, LOCK_EX|LOCK_NB) function to obtain a file lock. If the function fails to obtain a file lock, an error is returned. The failure may occur when the file lock is being used. You can retry or troubleshoot the failure.
    3. After the file lock is obtained, call the lseek(fd, 0, SEEK_END) function to set the current file offset of the file descriptor to the end of the file.
    4. Perform normal write operations. The insert position is located at the end of the file. The file lock is used to prevent overwriting.
    5. After a write operation is completed, call the flock(fd, LOCK_UN) function to release the file lock.
    The following code shows a sample program that is written in C.
    #define _GNU_SOURCE
    #include<stdlib.h>
    #include<stdio.h>
    #include<fcntl.h>
    #include<string.h>
    #include<unistd.h>
    #include<sys/file.h>
    #include<time.h>
    
    const char *OUTPUT_FILE = "/mnt/blog";
    int WRITE_COUNT = 50000;
    
    int do_lock(int fd)
    {
        int ret = -1;
        while (1)
        {
            ret = flock(fd, LOCK_EX | LOCK_NB);
            if (ret == 0)
            {
                break;
            }
            usleep((rand() % 10) * 1000);
        }
        return ret;
    }
    
    int do_unlock(int fd)
    {
        return flock(fd, LOCK_UN);
    }
    
    int main()
    {
            int fd = open(OUTPUT_FILE, O_WRONLY | O_APPEND | O_DIRECT);
            if (fd < 0)
            {
                    printf("Error Open\n");
                    exit(-1);
            }
            for (int i = 0; i < WRITE_COUNT; ++i)
            {
                    char *buf = "one line\n";
    
                    /* Lock file */
                    int ret = do_lock(fd);
                    if (ret != 0)
                    {
                            printf("Lock Error\n");
                            exit(-1);
                    }
    
                    /* Seek to the end */
                    ret = lseek(fd, 0, SEEK_END);
                    if (ret < 0)
                    {
                            printf("Seek Error\n");
                            exit(-1);
                    }
    
                    /* Write to file */
                    int n = write(fd, buf, strlen(buf));
                    if (n <= 0)
                    {
                            printf("Write Error\n");
                            exit(-1);
                    }
    
                    /* Unlock file */
                    ret = do_unlock(fd);
                    if (ret != 0)
                    {
                            printf("UnLock Error\n");
                            exit(-1);
                    }
            }
            return 0;
    }
                
    For more information about how to call the flock() function, visit http://www.hackinglinuxexposed.com/articles/20030616.html.
    Note To call the flock() function on a NAS file system, your Linux kernel version must be 2.6.12 or later. If you use Linux of an earlier kernel version, call the fcntl() function.

Why do I need to mount a NAS file system by using the noresvport parameter?

If network switchovers or high availability (HA) switchovers of backend services occur, the network of the file system has a low probability of being disrupted. In most cases, communication is restored within several minutes. In the worst scenario, you may need to restart the ECS instance to restore communication. After the noresvport is specified, communication is restored within only several seconds.

How can I troubleshoot and fix issues about the noresvport parameter?

Note This section is applicable only to Linux users. Windows users can skip this section.
  1. Check whether the noresvport parameter is specified when you mount a file system.
    1. Run the following command on an ECS Linux instance to download the check_noresvport.py script:
      wget -N https://code.aliyun.com/nas_team/nas-client-tools/raw/master/linux_client/check_noresvport.py -P /tmp/
    2. Run the following Python command to execute the script:
      python2.7 /tmp/check_noresvport.py -e
      If the "There is no issue for 'noresvport' on this ECS" message appears, skip the following steps.
  2. Fix issues about the noresvport parameter.
    Note We recommend that you fix these issues during off-peak hours.
    Use one of the following mount scenario-specific solutions to fix the issue:
    • If you mount a NAS file system on an ECS instance, run the following command to execute the script again.
      python2.7 /tmp/check_noresvport.py -e -r
    • If you mount a NAS file system on a container, run the following command to execute the script again on the node where the container resides.
      python2.7 /tmp/check_noresvport.py -e -c
  3. Update settings for an automatic mount.
    • If you have configured an automatic mount, update settings for the automatic mount and add the noresvport parameter. For more information, see Mount an NFS file system.
    • If no automatic mount is configured, skip this step.
    After the preceding steps are completed, repeat Step 1 and verify the result. If you have further questions, join the DingTalk group 23110762 for customer service.

In which cases do network switchovers or HA switchovers of backend services occur?

Aspara File Storage NAS provides stable and continuous file storage services. However, network switchovers or HA switchovers for backend services may still occur with a low probability. HA switchovers for backend services may occur due to service upgrades. However, the client network has a low probability of being disrupted by these switchovers. Before service upgrades, Alibaba Cloud sends notifications that include information about the upgrade schedules to all relevant users. This leaves you sufficient time to apply the noresvport parameter. We recommend that you apply the noresvport parameter at your earliest opportunity. Even if no upgrade is scheduled at the backend, you can still apply the noresvport parameter. This prevents failures that occur to file systems due to other unexpected issues. These issues include changes on Server Load Balancer (SLB) instances, hardware failures at the backend, and other cases that may trigger switchovers.

Why must I mount the file system again? Are other solutions to the issue available?

You need to remount the file system to close all previous TCP connections to which the noresvport parameter is not applied. Then, you must establish new TCP connections by using the noresvport parameter. To close all previous TCP connections, you must stop all services that are related to NAS file systems. Then, you can run the umount command to unmount the file system.

If you do not want to mount the file system again, we recommend that you create a mount target based on a new file system. In this case, you need to mount the new file system on another local directory. You can migrate all services to the new local directory. Then, you can disable the previous mount directory and mount target.