FAQ SearchLogin
Tuxera Home
View unanswered posts | View active topics It is currently Wed Jul 28, 2021 16:56



Post new topic Reply to topic  [ 10 posts ] 
Ntfs program opening files on other mount points? 
Author Message

Joined: Thu Jul 09, 2009 17:09
Posts: 7
Post Ntfs program opening files on other mount points?
I use ntfs-3g heavily, but when running a program that mounts and reads files in multiple threads I'm running into a umount issue.

Basically the umount of an ntfs-3g mount point is being blocked because the pid of another ntfs-3g program (mounting a separate device at a separate mount point,) has an open file handle to the file system that I'm trying to umount.

I'm curious how that scenario would even be possible without a bug in fuse, ntfs-3g, or somewhere else? I'd suspect my code, but I'm not sure how I'd even get it to happen if I wanted to try.

What I see:
umount: /gold_image/p4/bbuckley_main_ca/source/ca/dv/smpM1A9C31CE0000022D_P1A9C31CE00000227100: device is busy

I go to check to see what is blocking that unmount:
[root@localhost ca]# lsof |grep /gold_image/p4/bbuckley_main_ca/source/ca/dv/smpM1A9C31CE0000022D_P1A9C31CE00000227100
ntfs-3g 30242 root 228r REG 65,129 20554464 64 /gold_image/p4/bbuckley_main_ca/source/ca/dv/smpM1A9C31CE0000022D_P1A9C31CE00000227100/Program Files/Unidesk/Uniservice/package_app_rules_1a9c31ce00000227

Look up the pid of the ntfs-3g that has that file handle open:
[root@localhost ca]# ps -aef |grep 302422
root 30242 1 0 Apr29 ? 00:00:01 ntfs-3g /dev/sdt1 /gold_image/p4/bbuckley_main_ca/source/ca/dv/smpM1A9C31CE00000221_P1A9C31CE000001401200 -o force,case_insensitive,ro

Note that the pid hold that open is for a different device and mount point. Here is the pid/device of the ntfs-3g process that I'm trying to close:

[root@localhost ca]# ps -aef |grep
root 26745 1 0 Apr29 ? 00:00:00 ntfs-3g /dev/sdy1 /gold_image/p4/bbuckley_main_ca/source/ca/dv/smpM1A9C31CE0000022D_P1A9C31CE00000227100 -o force,case_insensitive,ro

Not sure why, give two read only ntfs-3g processes, one process would be holding an open file handle in another process?? It can get bad enough that it result in deadlocks at times where the unmount of ntfs-3g process 1 is blocked by ntfs-3g process 2, which in turn is blocked by ntfs-3g process 3, etc.

Here are some system information essentials:
[root@localhost ca]# ntfs-3g
ntfs-3g: No device is specified.

ntfs-3g 2010.1.16AR.1 integrated FUSE 27 - Third Generation NTFS Driver
Configuration type 1, XATTRS are on, POSIX ACLS are off

Copyright (C) 2005-2007 Yura Pakhuchiy
Copyright (C) 2006-2009 Szabolcs Szakacsits
Copyright (C) 2007-2010 Jean-Pierre Andre
Copyright (C) 2009 Erik Larsson

Usage: ntfs-3g [-o option[,...]] <device|image_file> <mount_point>

Options: ro (read-only mount), remove_hiberfile, uid=, gid=,
umask=, fmask=, dmask=, streams_interface=.
Please see the details in the manual (type: man ntfs-3g).

Example: ntfs-3g /dev/sda1 /mnt/windows

Ntfs-3g news, support and information: http://ntfs-3g.org
[root@localhost ca]# modinfo fuse
filename: /lib/modules/2.6.18-92.1.22.el5/kernel/fs/fuse/fuse.ko
alias: char-major-10-229
license: GPL
description: Filesystem in Userspace
author: Miklos Szeredi <miklos@szeredi.hu>
srcversion: 2741E1EF80D96D3C1FB8BE9
depends:
vermagic: 2.6.18-92.1.22.el5 SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1
[root@localhost ca]# uname -a
Linux localhost.localdomain 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 12:03:43 EST 2008 i686 i686 i386 GNU/Linux


Fri Apr 30, 2010 15:05
Profile

Joined: Thu Jan 28, 2010 17:17
Posts: 6
Post Re: Ntfs program opening files on other mount points?
I used to unmount the ntfs-3g mounted files with umount -l.

Will this serve your purpose.

Regards
Rajesh


Mon May 03, 2010 20:01
Profile

Joined: Thu Jul 09, 2009 17:09
Posts: 7
Post Re: Ntfs program opening files on other mount points?
I can try a lazy unmount to see if it at least allows that thread/process to continue. However as this application keeps the system pretty busy I will be apprehensive about this solution as it will still leave hanging file handles around for some amount of time. I'd still like to understand where this behavior is originating from as it seems like an ntfs-3g bug (or perhaps a fuse bug?)


Tue May 04, 2010 20:04
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: Ntfs program opening files on other mount points?
Hi,

Quote:
I can try a lazy unmount to see if it at least allows that thread/process to continue. However as this application keeps the system pretty busy

Why would the system be kept busy ? Your application is assumed to have all its threads terminated before you umount.
Quote:
I'd still like to understand where this behavior is originating from as it seems like an ntfs-3g bug (or perhaps a fuse bug?)

ntfs-3g read files from other mountpoints only in very specific circumstances (eg redirected user mapping).

Is the blocked umount specific to ntfs-3g 2010.1.16AR.1 ?

Regards

Jean-Pierre


Sun May 09, 2010 19:26
Profile

Joined: Thu Jul 09, 2009 17:09
Posts: 7
Post Re: Ntfs program opening files on other mount points?
I do not believe that this problem is specific to this version of ntfs-3g. I've been seeing this behavior for the past year and I've gone through a number of upgrades to pick up various fixes.

As for keeping the system busy, my application is going multiple things with multiple ntfs partitions at once. So the piece of work that is unmount a specific partition on a specific device is done with it, but other processes are using other devices and ntfs partitions (hence the problem.) Furthermore, once the job that is "blocked" unmounts that partition and device, a new device may be hot swapped in and have the partition on that device will be mounted to a new mount point. I'm worried that a lazy unmount is asking for trouble later on since a stale file handle will still be outstanding to a device that is being used for something different now.

Basically, even if lazy unmounts allow the "blocked" thread/process to continue, I'm still worried that it's a hack to get around what seems like a bug. If it is a real bug I may just be pushing the impact of that bug to a different area of my system.


Mon May 10, 2010 18:42
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: Ntfs program opening files on other mount points?
Hi,

Quote:
As for keeping the system busy, my application is going multiple things with multiple ntfs partitions at once. So the piece of work that is unmount a specific partition on a specific device is done with it, but other processes are using other devices and ntfs partitions

So some thread having accessed the partition to unmount is still active, possibly holding resources related to several partitions.... This will be difficult to analyze unless you can trigger the behavior in a simplified application.

Unrelated to this behavior, I see you mount with an option "case_insensitive" which does not exist. Just wanting to mention that since ntfs-3g-2010.3.6AR.2 there is a driver variant lowntfs-3g which has an option "ignore_case" to support case insensitive file names.

Regards

Jean-Pierre


Mon May 10, 2010 22:29
Profile

Joined: Wed Dec 15, 2010 19:16
Posts: 2
Post Re: Ntfs program opening files on other mount points?
I also have this problem!

I have two removable ntfs drives.

I mount drive 1 and then mount drive 2 using ntfs3g /dev/sdb1 /mnt/drive1.
This call to ntfs-3g is done in my application through a system(3) call.

I umount the drive 1 whilst drive 2 is mounted.

When I remount drive 1, it will now have file handles to the files that are on drive 2.

Here is some example "lsof" output to show what happens.

Before the problem:

my_application 1111 /mnt/drive2/file1
my_application 1111 /mnt/drive2/file2

After the problem

my_application 1111 /mnt/drive2/file1
my_application 1111 /mnt/drive2/file2
ntfs3g 3333 /mnt/drive2/file1
ntfs3g 3333 /mnt/drive2/file2

Now if I look at the process list:
...
my_application 1111
ntfs-3g 2222 /dev/sdc1 /mnt/drive2
ntfs-3g 3333 /dev/sdb1 /mnt/drive1

If you look closely, you notice that pid 3333 is meant to mount drive 1 and it does mount drive 1, but it also has file handles to /mnt/drive2! This stops me from being able to unmount drive2.

My application closes it's handles to file1 and file2 on drive 2 and tries to unmount drive 2 using umount(8). This fails because ntfs-3g has files open! Ths stops me from ejecting the drive!

I hope you have enough information to investigate the problem further. Thanks for your time and help.


Wed Dec 15, 2010 19:32
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: Ntfs program opening files on other mount points?
Hi ntfsuser,

I have successfully reproduced your situation. I summarize the first steps :

system("mount dev1 mntp1");
open("mntp1/file1", O_RDONLY);
system("mount dev2 mntp2");
close(file1);

At this stage, lsof shows that the second ntfs-3g process dealing with dev2 has an open descriptor on file1. I think this boils down to the system(3) call doing a fork(2), thus duplicating the open file descriptor, and the ntfs-3g process not being designed to close it.

To avoid this, you should make the system(3) call when no files are open.

Note : this could also be the explanation for the situation encountered by BBDev

Regards

Jean-Pierre


Thu Dec 16, 2010 16:47
Profile

Joined: Wed Dec 15, 2010 19:16
Posts: 2
Post Re: Ntfs program opening files on other mount points?
Hi, thanks for your reply, I just checked back to say that I dug a littler futher and realised the same thing, it is the child process inheriting the open file descriptors. Thanks for your help!


Fri Dec 17, 2010 16:37
Profile

Joined: Thu Jul 09, 2009 17:09
Posts: 7
Post Re: Ntfs program opening files on other mount points?
That was indeed the problem that I was seeing; we fixed it by closing all other file systems after the fork.


Thu Dec 08, 2011 00:23
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Original forum style by Vjacheslav Trushkin.