Skip to content

Commit 0b55943

Browse files
committed
add conditional compiling for statx, renameat in fiber module
1 parent 3f557c5 commit 0b55943

File tree

7 files changed

+61
-16
lines changed

7 files changed

+61
-16
lines changed

lib_fiber/c/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
126126
ifeq ($(has_io_uring), yes)
127127
CFLAGS += -DHAS_IO_URING
128128
endif
129+
ifeq ($(HAS_STATX), yes)
130+
CFLAGS += -DHAS_STATX
131+
endif
132+
ifeq ($(HAS_RENAMEAT2), yes)
133+
CFLAGS += -DHAS_RENAMEAT2
134+
endif
129135
endif
130136

131137
# For CYGWIN

lib_fiber/c/src/event.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,22 @@ struct FILE_EVENT {
154154
#define EVENT_FILE_CLOSE (unsigned) (1 << 12)
155155
#define EVENT_FILE_CANCEL (unsigned) (1 << 13)
156156
#define EVENT_FILE_UNLINK (unsigned) (1 << 14)
157-
#define EVENT_FILE_STATX (unsigned) (1 << 15)
158-
#define EVENT_FILE_RENAMEAT2 (unsigned) (1 << 16)
159-
#define EVENT_DIR_MKDIRAT (unsigned) (1 << 17)
160-
#define EVENT_SPLICE (unsigned) (1 << 18)
161-
162-
#define EVENT_READV (unsigned) (1 << 19)
163-
#define EVENT_RECV (unsigned) (1 << 20)
164-
#define EVENT_RECVFROM (unsigned) (1 << 21)
165-
#define EVENT_RECVMSG (unsigned) (1 << 22)
166-
167-
#define EVENT_WRITEV (unsigned) (1 << 23)
168-
#define EVENT_SEND (unsigned) (1 << 24)
169-
#define EVENT_SENDTO (unsigned) (1 << 25)
170-
#define EVENT_SENDMSG (unsigned) (1 << 26)
157+
#define EVENT_FILE_STAT (unsigned) (1 << 15)
158+
#define EVENT_FILE_STATX (unsigned) (1 << 16)
159+
#define EVENT_FILE_RENAMEAT (unsigned) (1 << 17)
160+
#define EVENT_FILE_RENAMEAT2 (unsigned) (1 << 18)
161+
#define EVENT_DIR_MKDIRAT (unsigned) (1 << 19)
162+
#define EVENT_SPLICE (unsigned) (1 << 20)
163+
164+
#define EVENT_READV (unsigned) (1 << 21)
165+
#define EVENT_RECV (unsigned) (1 << 22)
166+
#define EVENT_RECVFROM (unsigned) (1 << 23)
167+
#define EVENT_RECVMSG (unsigned) (1 << 24)
168+
169+
#define EVENT_WRITEV (unsigned) (1 << 25)
170+
#define EVENT_SEND (unsigned) (1 << 26)
171+
#define EVENT_SENDTO (unsigned) (1 << 27)
172+
#define EVENT_SENDMSG (unsigned) (1 << 28)
171173
#endif // HAS_IO_URING
172174

173175
event_proc *r_proc;
@@ -256,7 +258,9 @@ struct FILE_EVENT {
256258
socklen_t len;
257259
} peer;
258260

261+
#ifdef HAS_STATX
259262
struct statx *statxbuf;
263+
#endif
260264
char *path;
261265
} var;
262266

lib_fiber/c/src/event/event_io_uring.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ void event_uring_file_unlink(EVENT *ev, FILE_EVENT *fe, const char *pathname)
252252
TRY_SUBMMIT(ep);
253253
}
254254

255+
#ifdef HAS_STATX
255256
void event_uring_file_statx(EVENT *ev, FILE_EVENT *fe, int dirfd,
256257
const char *pathname, int flags, unsigned int mask,
257258
struct statx *statxbuf)
@@ -264,7 +265,9 @@ void event_uring_file_statx(EVENT *ev, FILE_EVENT *fe, int dirfd,
264265
io_uring_sqe_set_data(sqe, &fe->reader_ctx);
265266
TRY_SUBMMIT(ep);
266267
}
268+
#endif
267269

270+
#ifdef HAS_RENAMEAT2
268271
void event_uring_file_renameat2(EVENT *ev, FILE_EVENT *fe, int olddirfd,
269272
const char *oldpath, int newdirfd, const char *newpath, unsigned flags)
270273
{
@@ -276,6 +279,7 @@ void event_uring_file_renameat2(EVENT *ev, FILE_EVENT *fe, int olddirfd,
276279
io_uring_sqe_set_data(sqe, &fe->reader_ctx);
277280
TRY_SUBMMIT(ep);
278281
}
282+
#endif
279283

280284
void event_uring_mkdirat(EVENT *ev, FILE_EVENT *fe, int dirfd,
281285
const char *pathname, mode_t mode)
@@ -468,7 +472,9 @@ static void handle_one(EVENT *ev, IO_URING_CTX *ctx, int res)
468472
| EVENT_FILE_CANCEL \
469473
| EVENT_FILE_OPENAT \
470474
| EVENT_FILE_UNLINK \
475+
| EVENT_FILE_STAT \
471476
| EVENT_FILE_STATX \
477+
| EVENT_FILE_RENAMEAT \
472478
| EVENT_FILE_RENAMEAT2 \
473479
| EVENT_DIR_MKDIRAT \
474480
| EVENT_SPLICE)

lib_fiber/c/src/event/event_io_uring.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ void event_uring_file_cancel(EVENT *ev, FILE_EVENT *fe_orig, FILE_EVENT *fe);
1212
void event_uring_file_openat(EVENT* ev, FILE_EVENT *fe, int dirfd,
1313
const char* pathname, int flags, mode_t mode);
1414
void event_uring_file_unlink(EVENT *ev, FILE_EVENT *fe, const char *pathname);
15+
16+
# ifdef HAS_STATX
1517
void event_uring_file_statx(EVENT *ev, FILE_EVENT *fe, int dirfd,
1618
const char *pathname, int flags, unsigned int mask,
1719
struct statx *statxbuf);
20+
# endif
21+
22+
# ifdef HAS_RENAMEAT2
1823
void event_uring_file_renameat2(EVENT *ev, FILE_EVENT *fe, int olddirfd,
1924
const char *oldpath, int newdirfd, const char *newpath, unsigned flags);
25+
# endif
26+
2027
void event_uring_mkdirat(EVENT *ev, FILE_EVENT *fe, int dirfd,
2128
const char *pathname, mode_t mode);
2229
void event_uring_splice(EVENT *ev, FILE_EVENT *fe, int fd_in, loff_t off_in,

lib_fiber/c/src/hook/file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "hook.h"
99

1010
#define _GNU_SOURCE
11-
#include <fcntl.h>
1211
#include <sys/types.h>
1312
#include <sys/stat.h>
1413
#include <fcntl.h>
@@ -265,6 +264,7 @@ int unlink(const char *pathname)
265264
}
266265
}
267266

267+
#ifdef HAS_RENAMEAT2
268268
int renameat2(int olddirfd, const char *oldpath,
269269
int newdirfd, const char *newpath, unsigned int flags)
270270
{
@@ -311,12 +311,14 @@ int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpat
311311
{
312312
return renameat2(olddirfd, oldpath, newdirfd, newpath, 0);
313313
}
314+
#endif
314315

315316
int rename(const char *oldpath, const char *newpath)
316317
{
317318
return renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath);
318319
}
319320

321+
# ifdef HAS_STATX
320322
int statx(int dirfd, const char *pathname, int flags, unsigned int mask,
321323
struct statx *statxbuf)
322324
{
@@ -337,7 +339,7 @@ int statx(int dirfd, const char *pathname, int flags, unsigned int mask,
337339
FILE_ALLOC(fe, EVENT_FILE_STATX);
338340
fe->in.read_ctx.buf = strdup(pathname);
339341
fe->var.statxbuf = (struct statx*) malloc(sizeof(struct statx));
340-
memcpy(fe->var.statxbuf, statxbuf, sizeof(struct statx));
342+
//memcpy(fe->var.statxbuf, statxbuf, sizeof(struct statx));
341343

342344
event_uring_file_statx(ev, fe, dirfd, fe->in.read_ctx.buf, flags, mask,
343345
fe->var.statxbuf);
@@ -388,6 +390,7 @@ int stat(const char *pathname, struct stat *statbuf)
388390
statbuf->st_ctim.tv_sec = statxbuf.stx_ctime.tv_sec;
389391
return 0;
390392
}
393+
#endif
391394

392395
int mkdirat(int dirfd, const char *pathname, mode_t mode)
393396
{

lib_fiber/c/src/hook/hook.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ openat_fn __sys_openat = NULL;
9696
openat_fn *sys_openat = NULL;
9797
unlink_fn __sys_unlink = NULL;
9898
unlink_fn *sys_unlink = NULL;
99+
# ifdef HAS_STATX
99100
statx_fn __sys_statx = NULL;
100101
statx_fn *sys_statx = NULL;
102+
# endif
103+
# ifdef HAS_RENAMEAT2
101104
renameat2_fn __sys_renameat2 = NULL;
102105
renameat2_fn *sys_renameat2 = NULL;
106+
# endif
103107
mkdirat_fn __sys_mkdirat = NULL;
104108
mkdirat_fn *sys_mkdirat = NULL;
105109
splice_fn __sys_splice = NULL;
@@ -258,8 +262,12 @@ static void hook_api(void)
258262
# ifdef HAS_IO_URING
259263
LOAD_FN("openat", openat_fn, __sys_openat, sys_openat);
260264
LOAD_FN("unlink", unlink_fn, __sys_unlink, sys_unlink);
265+
# ifdef HAS_STATX
261266
LOAD_FN("statx", statx_fn, __sys_statx, sys_statx);
267+
# endif
268+
# ifdef HAS_RENAMEAT2
262269
LOAD_FN("renameat2", renameat2_fn, __sys_renameat2, sys_renameat2);
270+
# endif
263271
LOAD_FN("mkdirat", mkdirat_fn, __sys_mkdirat, sys_mkdirat);
264272
LOAD_FN("splice", splice_fn, __sys_splice, sys_splice);
265273
# endif

lib_fiber/c/src/hook/hook.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,15 @@ typedef int (*epoll_ctl_fn)(int, int, int, struct epoll_event *);
7575
# ifdef HAS_IO_URING
7676
typedef int (*openat_fn)(int, const char *, int, mode_t);
7777
typedef int (*unlink_fn)(const char *);
78+
79+
# ifdef HAS_STATX
7880
typedef int (*statx_fn)(int dirfd, const char *, int, unsigned int, struct statx *);
81+
# endif
82+
83+
# ifdef HAS_RENAMEAT2
7984
typedef int (*renameat2_fn)(int, const char *, int, const char *, unsigned);
85+
# endif
86+
8087
typedef int (*mkdirat_fn)(int, const char *, mode_t);
8188
typedef ssize_t (*splice_fn)(int, loff_t *, int, loff_t *, size_t, unsigned);
8289
# endif
@@ -177,8 +184,12 @@ extern ssize_t file_sendfile(socket_t out_fd, int in_fd, off64_t *off, size_t cn
177184

178185
extern openat_fn *sys_openat;
179186
extern unlink_fn *sys_unlink;
187+
# ifdef HAS_STATX
180188
extern statx_fn *sys_statx;
189+
# endif
190+
# ifdef HAS_RENAMEAT2
181191
extern renameat2_fn *sys_renameat2;
192+
# endif
182193
extern mkdirat_fn *sys_mkdirat;
183194
extern splice_fn *sys_splice;
184195
# endif

0 commit comments

Comments
 (0)