public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [RFC] Dependency hell on static inline forced by off_t + _GNU_SOURCE
@ 2024-04-12 11:46 Petr Vorel
  2024-04-12 12:16 ` Jan Stancek
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2024-04-12 11:46 UTC (permalink / raw)
  To: Cyril Hrubis, Li Wang, Jan Stancek; +Cc: ltp

Hi there,

I have following function:

#include "tst_fs.h"
#include "lapi/fallocate.h"

#define SAFE_FALLOCATE(fd, mode, offset, len) \
	safe_access(__FILE__, __LINE__, (path), (mode), (offset), (len), #mode)

static inline int safe_fallocate(const char *file, const int lineno,
	int fd, int mode, off_t offset, off_t len, const char *smode)
{
	int rval;

	rval = fallocate(fd, mode, offset, len);

	if (rval == -1) {
		if (tst_fs_type_(NULL, ".") == TST_NFS_MAGIC && (errno == EOPNOTSUPP ||
							  errno == ENOSYS)) {
			tst_brk_(file, lineno, TCONF | TERRNO,
					 "fallocate(%d, %s, %ld, %ld) unsupported",
					 fd, smode, (long)offset, (long)len);
		}
		tst_brk_(file, lineno, TBROK | TERRNO,
				 "fallocate(%d, %s, %ld, %ld) failed",
				 fd, smode, (long)offset, (long)len);
	} else if (rval < 0) {
		tst_brk_(file, lineno, TBROK | TERRNO,
			"Invalid fallocate(%d, %s, %ld, %ld) return value %d",
				 fd, smode, (long)offset, (long)len, rval);
	}

	return rval;
}

I have no idea where to put it.
1) fallocate() requires '#define _GNU_SOURCE'
2) fallocate() off_t parameter requires to be in a header (see 9120d8a22 and
3f571da28).
3) Use of tst_fs_type_(NULL, ".") and TBROK etc requires tst_test.h.

I tried to put it into:

a) include/tst_safe_macros_inline.h
Natural choice, but that would require to add to include/tst_test.h:

#ifndef  _GNU_SOURCE
# define _GNU_SOURCE
#endif

because it includes tst_safe_macros.h.  Which means whole new API started to use
_GNU_SOURCE. Would it be OK?  I don't think so.

And #define _GNU_SOURCE into tst_test.c and few other lib/*.c sources (not that dramatic),
because we cannot rely on <fcntl.h> not being loaded before #define _GNU_SOURCE.

b) include/lapi/fallocate.h
I'm not sure if this is against LTP lapi conventions, because it would require
lapi header include tst_test.h due tst_fs_type_ and TBROK. Also, we'd make it
new API dependent (thus use tst_fs_type(".") instead of tst_fs_type_(NULL, ".")

Also we have error on fallocate01.c which is still old API:

from fallocate01.c:103:
../../../../include/tst_test.h:11:3: error: #error Oldlib test.h already included
   11 | # error Oldlib test.h already included

I could rewrite fallocate01.c and fallocate02.c first, so that there is nothing
using old API which also uses include/lapi/fallocate.h.

Another solution would be to pass int parameter fsmagic so that the caller would
have to run tst_fs_type(".") itself.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-24 20:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-12 11:46 [LTP] [RFC] Dependency hell on static inline forced by off_t + _GNU_SOURCE Petr Vorel
2024-04-12 12:16 ` Jan Stancek
2024-04-12 13:19   ` Petr Vorel
2024-04-24 20:49     ` Edward Liaw via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox