linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matej Kupljen <matej.kupljen@gmail.com>
To: Hugh Dickins <hughd@google.com>
Cc: linux-mm@kvack.org
Subject: Fwd: tmpfs inode leakage when opening file with O_TMP_FILE
Date: Tue, 12 Feb 2019 08:44:57 +0100	[thread overview]
Message-ID: <CAHMF36HKu7S8ezhSbCcNcgwL0cHAVsB_6W1o4PE=rRgVQbMycw@mail.gmail.com> (raw)
In-Reply-To: <CAHMF36F4JN44Y-yMnxw36A8cO0yVUQhAkvJDcj_gbWbsuUAA5A@mail.gmail.com>

Hi all,

I sent this mail yesterday to kernel mailing list, but I got no reply.
So, I checked the MAINTAINERS file and I have found these emails.
I hope this is the right address for this issue.

Thanks and BR,
Matej

---------- Forwarded message ---------
From: Matej Kupljen <matej.kupljen@gmail.com>
Date: Mon, Feb 11, 2019 at 3:18 PM
Subject: tmpfs inode leakage when opening file with O_TMP_FILE
To: <linux-kernel@vger.kernel.org>


Hi,

it seems that when opening file on file system that is mounted on
tmpfs with the O_TMPFILE flag and using linkat call after that, it
uses 2 inodes instead of 1.

This is simple test case:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/limits.h>
#include <errno.h>

#define TEST_STRING     "Testing\n"

#define TMP_PATH        "/tmp/ping/"
#define TMP_FILE        "file.txt"


int main(int argc, char* argv[])
{
        char path[PATH_MAX];
        int fd;
        int rc;

        fd = open(TMP_PATH, __O_TMPFILE | O_RDWR,
                        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH | S_IWOTH);

        rc = write(fd, TEST_STRING, strlen(TEST_STRING));

        snprintf(path, PATH_MAX,  "/proc/self/fd/%d", fd);
        linkat(AT_FDCWD, path, AT_FDCWD, TMP_PATH TMP_FILE, AT_SYMLINK_FOLLOW);
        close(fd);

        return 0;
}

I have checked indoes with "df -i" tool. The first inode is used when
the call to open is executed and the second one when the call to
linkat is executed.
It is not decreased when close is executed.

I have also tested this on an ext4 mounted fs and there only one inode is used.

I tested this on:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"

$ uname -a
Linux Orion 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC
2018 x86_64 x86_64 x86_64 GNU/Linux

If you need any more information, please let me know.

And please CC me when replying, I am not subscribed to the list.

Thanks and BR,
Matej


       reply	other threads:[~2019-02-12  7:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAHMF36F4JN44Y-yMnxw36A8cO0yVUQhAkvJDcj_gbWbsuUAA5A@mail.gmail.com>
2019-02-12  7:44 ` Matej Kupljen [this message]
2019-02-12 19:07   ` Hugh Dickins
     [not found] ` <20190214154402.5d204ef2aa109502761ab7a0@linux-foundation.org>
2019-02-15  0:26   ` Darrick J. Wong
2019-02-15 10:38     ` Hugh Dickins
2019-02-19  4:23       ` Hugh Dickins
2019-02-19  4:34         ` Darrick J. Wong

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='CAHMF36HKu7S8ezhSbCcNcgwL0cHAVsB_6W1o4PE=rRgVQbMycw@mail.gmail.com' \
    --to=matej.kupljen@gmail.com \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox