VM Mapped Network Drive (SMB) With Open Files Being Corrupted When Mover Runs


Go to solution Solved by limetech,

Recommended Posts

It would be helpful to understand how Mover determines whether a file is safe to move. What I'm observing is for fairly large move operations, it seems like some files that are actively written to by a VM with a mapped SMB share (via virtio adapter) is being moved, causing the host VM to report an error when writing to the file.

 

When I do a simple test of a single open file, Mover seems to correctly skip over the open file. Via a terminal:

root@Tower:~# smbstatus -L

Locked files:
Pid          User(ID)   DenyMode   Access      R/W        Oplock           SharePath   Name   Time
--------------------------------------------------------------------------------------------------
343          1000       DENY_NONE  0x12019f    RDWR       LEASE(RWH)       /mnt/primary/system/shares/pdb   Incoming/video.mp4.part   Wed Jun 21 12:11:39 2023
343          1000       DENY_NONE  0x100081    RDONLY     NONE             /mnt/primary/system/shares/pdb   .   Wed Jun 21 12:16:57 2023

And from the syslog when I trigger Mover:

Jun 21 12:34:53 Tower move: mover: started
Jun 21 12:34:53 Tower move: skip: /mnt/cache/Archive/Tower/20230428/video.mp4.part
Jun 21 12:34:53 Tower move: mover: finished

 

However, if there are a lot of files that need to be moved, then I'm seeing those open files being moved. Anecdotally, it seems to happen if the file is opened after Mover is initiated (but it's hard to confirm). Could it be that Mover is checking the file permissions when the operation starts, but if the permissions change during the run then this causes the behavior I'm seeing?

 

I've attached my smb.conf to see if that has anything to do with it. I'll admit I have a slightly convoluted share scheme where I have symlink'd `/mnt/cache/Archive/Tower/20230428/` to `/mnt/primary/system/shares/pdb/Incoming` and I create a custom share for the `/mnt/primary/system/shares/pdb` directory (this is to combine several shared folders into one and so I only need a single mapped drive inside of the VM).

 

 

smb.conf

Link to comment

Okay, digging into it a bit more, it actually seems like maybe it's a different problem. The issue seems to be that if Mover starts moving files from a directory, the whole directory is locked or something and prevents writes. Is that expected behavior?

Link to comment
  • Solution
23 hours ago, jch said:

It would be helpful to understand how Mover determines whether a file is safe to move

 

Mover invokes

 /usr/local/sbin/in_use filename

If this returns 0 (success) then file is not moved.

 

Here is the in_use script:
 

#!/bin/bash
#Copyright 2005-2016, Lime Technology
#License: GPLv2 only

# usage: in_use <file>
# returns exit status 0 (success) if in-use, 1 if not
# used to check if a file is "in use", ie:
# - if any process has the file open, or
# - if file is loopback mounted

FILE=$1
# if file is on user share, check dereferenced file
if [[ "$FILE" == /mnt/user/* ]]; then
  DISK=$(getfattr -n system.LOCATION --absolute-names --only-values "$FILE" 2>/dev/null)
  FILE="${FILE/user/$DISK}"
fi
fuser -s "$FILE" && exit
[[ $(losetup -j "$FILE") ]] && exit
exit 1

 

Link to comment
  • 1 month later...

Is the `in_use` command invoked by the `/usr/local/bin/move` binary itself? I don't see any calls to the `in_use` command in the `/usr/local/sbin/mover` file.

 

On 6/22/2023 at 12:21 PM, limetech said:

 

Mover invokes

 /usr/local/sbin/in_use filename

If this returns 0 (success) then file is not moved.

 

Here is the in_use script:
 

#!/bin/bash
#Copyright 2005-2016, Lime Technology
#License: GPLv2 only

# usage: in_use <file>
# returns exit status 0 (success) if in-use, 1 if not
# used to check if a file is "in use", ie:
# - if any process has the file open, or
# - if file is loopback mounted

FILE=$1
# if file is on user share, check dereferenced file
if [[ "$FILE" == /mnt/user/* ]]; then
  DISK=$(getfattr -n system.LOCATION --absolute-names --only-values "$FILE" 2>/dev/null)
  FILE="${FILE/user/$DISK}"
fi
fuser -s "$FILE" && exit
[[ $(losetup -j "$FILE") ]] && exit
exit 1

 

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.