summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2022-01-05 12:21:28 -0700
committerJens Axboe <axboe@kernel.dk>2022-01-05 12:21:28 -0700
commit918d8061ffdfdf253806a1e8e141c71644e678bd (patch)
tree0923100f910e650e9ce170c76cf59e4d4fa0055f
parent515e03ef1a82e1b866209756bb18bea053988c9d (diff)
downloadliburing-918d8061ffdfdf253806a1e8e141c71644e678bd.tar.gz
liburing-918d8061ffdfdf253806a1e8e141c71644e678bd.tar.bz2
Remove getdents support
There are still discussions about the API, and hence the feature will miss the 5.17 kernel release. As the API is likely to change, remove the getdents support for now and we can re-add it when it's finalized. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--man/io_uring_prep_getdents.364
-rw-r--r--src/include/liburing.h6
-rw-r--r--src/include/liburing/io_uring.h1
-rw-r--r--test/Makefile1
-rw-r--r--test/getdents.c272
5 files changed, 0 insertions, 344 deletions
diff --git a/man/io_uring_prep_getdents.3 b/man/io_uring_prep_getdents.3
deleted file mode 100644
index 15279f6..0000000
--- a/man/io_uring_prep_getdents.3
+++ /dev/null
@@ -1,64 +0,0 @@
-.\" Copyright (C) 2021 Stefan Roesch <shr@fb.com>
-.\"
-.\" SPDX-License-Identifier: LGPL-2.0-or-later
-.\"
-.TH io_uring_prep_getdents 3 "November 19, 2021" "liburing-2.1" "liburing Manual"
-.SH NAME
-io_uring_prep_getdents - prepare getdents64 call
-
-.SH SYNOPSIS
-.nf
-.BR "#include <liburing.h>"
-.PP
-.BI "void io_uring_prep_getdents(struct io_uring_sqe *sqe,"
-.BI " int fd,"
-.BI " void *buf,"
-.BI " unsigned int count,"
-.BI " uint64_t offset)"
-
-.SH DESCRIPTION
-.PP
-The io_uring_prep_getdents() prepares a getdents64 request. The submission queue
-entry
-.I sqe
-is setup to use the file descriptor
-.I fd
-to start writing up to
-.I count
-bytes into the buffer
-.I buf
-starting at
-.I offset.
-
-After the getdents call has been prepared it can be submitted with one of the submit
-functions.
-
-.SH RETURN VALUE
-None
-
-.SH EXAMPLE
-A getdents io_uring call can be prepared like in the following code snippet.
-The io_uring_sqe_set_data(3) call is not necessary, but it helps to correlate the
-request with the results.
-
-.BI "void schedule_readdir(struct io_uring_sqe *sqe, struct dir *dir)"
-.fi
-.BI "{"
-.fi
-.BI " io_uring_prep_getdents(sqe,"
-.fi
-.BI " dir->fd,"
-.fi
-.BI " dir->buf,"
-.fi
-.BI " sizeof(dir->buf),"
-.fi
-.BI " dir->off);"
-.fi
-.BI " io_uring_sqe_set_data(sqe, dir);
-.fi
-.BI "}"
-
-
-.SH SEE ALSO
-.BR io_uring_get_sqe (3), io_uring_sqe_set_data (3), io_uring_submit (3), io_uring_sqe_get_data (3)
diff --git a/src/include/liburing.h b/src/include/liburing.h
index b2683c1..3050fcc 100644
--- a/src/include/liburing.h
+++ b/src/include/liburing.h
@@ -700,12 +700,6 @@ static inline void io_uring_prep_linkat(struct io_uring_sqe *sqe, int olddfd,
sqe->hardlink_flags = (__u32) flags;
}
-static inline void io_uring_prep_getdents(struct io_uring_sqe *sqe, int fd,
- void *buf, unsigned int count, uint64_t offset)
-{
- io_uring_prep_rw(IORING_OP_GETDENTS, sqe, fd, buf, count, offset);
-}
-
/*
* Returns number of unconsumed (if SQPOLL) or unsubmitted entries exist in
* the SQ ring
diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h
index d75ca47..a7d193d 100644
--- a/src/include/liburing/io_uring.h
+++ b/src/include/liburing/io_uring.h
@@ -147,7 +147,6 @@ enum {
IORING_OP_MKDIRAT,
IORING_OP_SYMLINKAT,
IORING_OP_LINKAT,
- IORING_OP_GETDENTS,
/* this goes last, obviously */
IORING_OP_LAST,
diff --git a/test/Makefile b/test/Makefile
index ccf4fde..7ccd657 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -78,7 +78,6 @@ test_srcs := \
file-verify.c \
fixed-link.c \
fsync.c \
- getdents.c \
hardlink.c \
io-cancel.c \
iopoll.c \
diff --git a/test/getdents.c b/test/getdents.c
deleted file mode 100644
index ac66f28..0000000
--- a/test/getdents.c
+++ /dev/null
@@ -1,272 +0,0 @@
-#include <assert.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/resource.h>
-#include <sys/xattr.h>
-#include <unistd.h>
-
-#include "helpers.h"
-#include "liburing.h"
-
-static int no_getdents;
-
-#define BUFFER_SIZE 512
-
-#define LIST_INIT(name) { &(name), &(name) }
-
-#define CONTAINER_OF(ptr, type, member) ( \
- { \
- const typeof(((type *)0)->member) *__ptr = (ptr); \
- (type *)((char *)__ptr - (intptr_t)(&((type *)0)->member)); \
- })
-
-struct list {
- struct list *next;
- struct list *prev;
-};
-
-struct dir {
- struct list list;
- int ret;
-
- struct dir *parent;
- int fd;
- uint64_t off;
- uint8_t buf[BUFFER_SIZE];
- char name[0];
-};
-
-struct linux_dirent64 {
- int64_t d_ino; /* 64-bit inode number */
- int64_t d_off; /* 64-bit offset to next structure */
- unsigned short d_reclen; /* Size of this dirent */
- unsigned char d_type; /* File type */
- char d_name[]; /* Filename (null-terminated) */
-};
-
-/* Define global variables. */
-static struct io_uring ring;
-static struct list active = LIST_INIT(active);
-static int sqes_in_flight = 0;
-static int num_dir_entries = 0;
-
-/* Forward declarations. */
-static void drain_cqes(void);
-static void schedule_readdir(struct dir *dir);
-
-/* List helper functions. */
-static inline void list_add_tail(struct list *l, struct list *head)
-{
- l->next = head;
- l->prev = head->prev;
- head->prev->next = l;
- head->prev = l;
-}
-
-static inline void list_del(struct list *l)
-{
- l->prev->next = l->next;
- l->next->prev = l->prev;
- l->prev = NULL;
- l->next = NULL;
-}
-
-static inline int is_list_empty(const struct list *l)
-{
- return l->next == l;
-}
-
-static struct io_uring_sqe *get_sqe(void)
-{
- struct io_uring_sqe *sqe;
-
- sqe = io_uring_get_sqe(&ring);
- while (sqe == NULL) {
- drain_cqes();
-
- int ret = io_uring_submit(&ring);
- if (ret < 0 && errno != EBUSY) {
- perror("io_uring_submit");
- exit(EXIT_FAILURE);
- }
-
- sqe = io_uring_get_sqe(&ring);
- }
-
- sqes_in_flight++;
- return sqe;
-}
-
-static void drain_cqes(void)
-{
- struct io_uring_cqe *cqe;
- uint32_t head;
- int count;
-
- count = 0;
- io_uring_for_each_cqe (&ring, head, cqe) {
- struct dir *dir;
-
- dir = io_uring_cqe_get_data(cqe);
-
- list_add_tail(&dir->list, &active);
- dir->ret = cqe->res;
-
- count++;
- }
-
- sqes_in_flight -= count;
- io_uring_cq_advance(&ring, count);
-}
-
-static void schedule_opendir(struct dir *parent, const char *name)
-{
- struct io_uring_sqe *sqe;
- int len = strlen(name);
- struct dir *dir;
-
- dir = malloc(sizeof(*dir) + len + 1);
- if (dir == NULL) {
- fprintf(stderr, "out of memory\n");
- exit(EXIT_FAILURE);
- }
-
- dir->parent = parent;
- dir->fd = -1;
- memcpy(dir->name, name, len);
- dir->name[len] = 0;
-
- sqe = get_sqe();
- io_uring_prep_openat(sqe,
- (parent != NULL) ? parent->fd : AT_FDCWD,
- dir->name,
- O_DIRECTORY,
- 0);
- io_uring_sqe_set_data(sqe, dir);
-}
-
-static void opendir_completion(struct dir *dir, int ret)
-{
- if (ret < 0) {
- fprintf(stderr, "error opening ");
- fprintf(stderr, ": %s\n", strerror(-ret));
- return;
- }
-
- dir->fd = ret;
- dir->off = 0;
- schedule_readdir(dir);
-}
-
-static void schedule_readdir(struct dir *dir)
-{
- struct io_uring_sqe *sqe;
-
- sqe = get_sqe();
- io_uring_prep_getdents(sqe, dir->fd, dir->buf, sizeof(dir->buf), dir->off);
- io_uring_sqe_set_data(sqe, dir);
-}
-
-static void readdir_completion(struct dir *dir, int ret)
-{
- uint8_t *bufp;
- uint8_t *end;
-
- if (ret < 0) {
- if (ret == -EINVAL) {
- fprintf(stdout, "Kernel doesn't support getdents, skipping\n");
- no_getdents = 1;
- return;
- }
- fprintf(stderr, "error reading ");
- fprintf(stderr, ": %s (%d)\n", strerror(-ret), ret);
- return;
- }
-
- if (ret == 0) {
- free(dir);
- return;
- }
-
- bufp = dir->buf;
- end = bufp + ret;
-
- while (bufp < end) {
- struct linux_dirent64 *dent;
-
- dent = (struct linux_dirent64 *)bufp;
-
- if (strcmp(dent->d_name, ".") && strcmp(dent->d_name, "..")) {
- if (dent->d_type == DT_DIR)
- schedule_opendir(dir, dent->d_name);
- }
-
- dir->off = dent->d_off;
- bufp += dent->d_reclen;
- ++num_dir_entries;
- }
-
- schedule_readdir(dir);
-}
-
-int main(int argc, char *argv[])
-{
- struct rlimit rlim;
-
- if (argc > 0)
- return 0;
-
- /* Increase number of files rlimit to 1M. */
- if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
- perror("getrlimit");
- return 1;
- }
-
- if (geteuid() == 0 && rlim.rlim_max < 1048576)
- rlim.rlim_max = 1048576;
-
- if (rlim.rlim_cur < rlim.rlim_max) {
- rlim.rlim_cur = rlim.rlim_max;
- setrlimit(RLIMIT_NOFILE, &rlim);
- }
-
- if (io_uring_queue_init(256, &ring, 0) < 0) {
- perror("io_uring_queue_init");
- return 1;
- }
-
- /* Submit and handle requests. */
- schedule_opendir(NULL, ".");
- while (sqes_in_flight) {
- int ret = io_uring_submit_and_wait(&ring, 1);
- if (ret < 0 && errno != EBUSY) {
- perror("io_uring_submit_and_wait");
- return 1;
- }
-
- drain_cqes();
-
- while (!is_list_empty(&active)) {
- struct dir *dir;
-
- dir = CONTAINER_OF(active.next, struct dir, list);
- list_del(&dir->list);
-
- if (dir->fd == -1)
- opendir_completion(dir, dir->ret);
- else
- readdir_completion(dir, dir->ret);
- if (no_getdents) {
- num_dir_entries = 50;
- goto done;
- }
- }
- }
-
-done:
- io_uring_queue_exit(&ring);
- return num_dir_entries < 50;
-}