mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-07-02 14:07:34 +03:00

Linux 3.11 add O_TMPFILE to open(2), which allow creating an unlinked file on supported filesystem. It's basically doing open(2) and unlink(2) atomically. The filesystem support is added through i_op->tmpfile. We basically copy the create operation except we get rid of the link and name related stuff and add the new node to unlinked set. We also add support for linkat(2) to link tmpfile. However, since all previous file operation will skip ZIL, we force a txg_wait_synced to make sure we are sync safe. Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
53 lines
981 B
C
53 lines
981 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
|
|
/* backward compat in case it's not defined */
|
|
#ifndef O_TMPFILE
|
|
#define O_TMPFILE (020000000|O_DIRECTORY)
|
|
#endif
|
|
|
|
/*
|
|
* DESCRIPTION:
|
|
* Check if the kernel support O_TMPFILE.
|
|
*/
|
|
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
struct stat buf;
|
|
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Usage: %s dir\n", argv[0]);
|
|
return (2);
|
|
}
|
|
if (stat(argv[1], &buf) < 0) {
|
|
perror("stat");
|
|
return (2);
|
|
}
|
|
if (!S_ISDIR(buf.st_mode)) {
|
|
fprintf(stderr, "\"%s\" is not a directory\n", argv[1]);
|
|
return (2);
|
|
}
|
|
|
|
fd = open(argv[1], O_TMPFILE | O_WRONLY, 0666);
|
|
if (fd < 0) {
|
|
/*
|
|
* Only fail on EISDIR. If we get EOPNOTSUPP, that means
|
|
* kernel support O_TMPFILE, but the path at argv[1] doesn't.
|
|
*/
|
|
if (errno == EISDIR) {
|
|
fprintf(stderr, "kernel doesn't support O_TMPFILE\n");
|
|
return (1);
|
|
}
|
|
perror("open");
|
|
} else {
|
|
close(fd);
|
|
}
|
|
return (0);
|
|
}
|