All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Cyril Hrubis <chrubis@suse.cz>, Li Wang <liwang@redhat.com>,
	Jan Stancek <jstancek@redhat.com>
Cc: ltp@lists.linux.it
Subject: [LTP] [RFC] Dependency hell on static inline forced by off_t + _GNU_SOURCE
Date: Fri, 12 Apr 2024 13:46:16 +0200	[thread overview]
Message-ID: <20240412114616.GB427746@pevik> (raw)

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

             reply	other threads:[~2024-04-12 11:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 11:46 Petr Vorel [this message]
2024-04-12 12:16 ` [LTP] [RFC] Dependency hell on static inline forced by off_t + _GNU_SOURCE Jan Stancek
2024-04-12 13:19   ` Petr Vorel
2024-04-24 20:49     ` Edward Liaw via ltp

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=20240412114616.GB427746@pevik \
    --to=pvorel@suse.cz \
    --cc=chrubis@suse.cz \
    --cc=jstancek@redhat.com \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.