All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerhard Heift <ml-nfs-linux-20110412-ef47@gheift.de>
To: linux-nfs@vger.kernel.org
Subject: nfsdv4 leaks file descriptors
Date: Tue, 12 Apr 2011 16:01:50 +0200	[thread overview]
Message-ID: <20110412140148.GA17242@gheift> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 959 bytes --]

Hello,

I have a linux kernel (2.6.38.2, armv5tel) running which exports a
directory with following options:

/data ip/32(rw,async,crossmnt,insecure,root_squash,no_subtree_check,fsid=0)

On the client (Debian unstable, kernel 2.6.38-2-amd64) I mounted the
directory under /media(nfs4import with

# mount -t nfs4 ip:/ /media/nfs4import

After a lot running fdupes on this folder the server kernel starts
throwing messages like this one:

  VFS: file-max limit [number] reached

After a reboot I recognised that the number of used file descriptors
increases during the run of fdupes (see /proc/sys/fs/file-nr). Even
after unmounting the exported filesystem on the client, unexport the
file system on the server and stopping the nfs-server the file
descriptors are still allocated and unmounting the filesystem is not
possible.

After a little bit of research I could create a small program, which
increases the used file descriptors by one.

Regards,
  Gerhard

[-- Attachment #1.2: leak-test.c --]
[-- Type: text/x-csrc, Size: 664 bytes --]

#include <stdio.h>

#define DIR "/media/nfs4import/"

int main(void) {
	FILE *f1;
	FILE *f2;
	char b[1024];
	int i;

	// create file1
	f1 = fopen(DIR "file1.txt", "w");
	fwrite("test\n", 5, 1, f1);
	close(f1);

	// open file1 in read mode
	f1 = fopen(DIR "file1.txt", "r");

	for (i = 0; i < 1; i++) {
		// open file2 in write mode and close it
		f2 = fopen(DIR "file2.txt", "w");
		fclose(f2);
	
		// open file2 in read mode and close it
		// this causes the leak of a file descriptor on the server
		// just watch /proc/sys/fs/file-nr on the server
		f2 = fopen(DIR "file2.txt", "r");
		fclose(f2);
	}
	fclose(f1);

	return 0;
}

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

             reply	other threads:[~2011-04-12 14:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12 14:01 Gerhard Heift [this message]
2011-04-13 21:12 ` nfsdv4 leaks file descriptors J. Bruce Fields
2011-04-14  5:48   ` Gerhard Heift
2011-04-14 19:10     ` J. Bruce Fields
2011-04-15 13:20       ` Gerhard Heift
2011-04-15 22:36         ` J. Bruce Fields
2011-04-20 11:08           ` Gerhard Heift
2011-04-20 15:30             ` J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110412140148.GA17242@gheift \
    --to=ml-nfs-linux-20110412-ef47@gheift.de \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.