Rename seq to seqc to avoid namespace clashes with Linux

Linux generates the content of procfs files using a mechanism prefixed with
seq_*. This in particular came up with recent gcov import.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mateusz Guzik 2019-02-27 22:56:55 +00:00
parent 75d6d57634
commit 55fda58146
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=344648
4 changed files with 62 additions and 60 deletions

View File

@ -38,6 +38,8 @@
# xargs -n1 | sort | uniq -d; # xargs -n1 | sort | uniq -d;
# done # done
# 20190227: rename seq.h to seqc.h
OLD_FILES+=usr/include/sys/seq.h
# 20190222: libifconfig made INTERNALLIB # 20190222: libifconfig made INTERNALLIB
OLD_FILES+=usr/lib/libprivateifconfig.a OLD_FILES+=usr/lib/libprivateifconfig.a
OLD_FILES+=usr/lib/libprivateifconfig_p.a OLD_FILES+=usr/lib/libprivateifconfig_p.a

View File

@ -304,11 +304,11 @@ fdfree(struct filedesc *fdp, int fd)
fde = &fdp->fd_ofiles[fd]; fde = &fdp->fd_ofiles[fd];
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_begin(&fde->fde_seq); seqc_write_begin(&fde->fde_seqc);
#endif #endif
fde->fde_file = NULL; fde->fde_file = NULL;
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_end(&fde->fde_seq); seqc_write_end(&fde->fde_seqc);
#endif #endif
fdefree_last(fde); fdefree_last(fde);
fdunused(fdp, fd); fdunused(fdp, fd);
@ -908,7 +908,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
* Duplicate the source descriptor. * Duplicate the source descriptor.
*/ */
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_begin(&newfde->fde_seq); seqc_write_begin(&newfde->fde_seqc);
#endif #endif
memcpy(newfde, oldfde, fde_change_size); memcpy(newfde, oldfde, fde_change_size);
filecaps_copy_finish(&oldfde->fde_caps, &newfde->fde_caps, filecaps_copy_finish(&oldfde->fde_caps, &newfde->fde_caps,
@ -918,7 +918,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
else else
newfde->fde_flags = oldfde->fde_flags & ~UF_EXCLOSE; newfde->fde_flags = oldfde->fde_flags & ~UF_EXCLOSE;
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_end(&newfde->fde_seq); seqc_write_end(&newfde->fde_seqc);
#endif #endif
td->td_retval[0] = new; td->td_retval[0] = new;
@ -1876,7 +1876,7 @@ _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
fde = &fdp->fd_ofiles[fd]; fde = &fdp->fd_ofiles[fd];
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_begin(&fde->fde_seq); seqc_write_begin(&fde->fde_seqc);
#endif #endif
fde->fde_file = fp; fde->fde_file = fp;
fde->fde_flags = (flags & O_CLOEXEC) != 0 ? UF_EXCLOSE : 0; fde->fde_flags = (flags & O_CLOEXEC) != 0 ? UF_EXCLOSE : 0;
@ -1885,7 +1885,7 @@ _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
else else
filecaps_fill(&fde->fde_caps); filecaps_fill(&fde->fde_caps);
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_end(&fde->fde_seq); seqc_write_end(&fde->fde_seqc);
#endif #endif
} }
@ -2567,7 +2567,7 @@ fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp,
filecaps_fill(havecapsp); filecaps_fill(havecapsp);
#else #else
struct file *fp; struct file *fp;
seq_t seq; seqc_t seq;
for (;;) { for (;;) {
error = fget_unlocked(fdp, fd, needrightsp, &fp, &seq); error = fget_unlocked(fdp, fd, needrightsp, &fp, &seq);
@ -2602,7 +2602,7 @@ fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp,
int int
fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
struct file **fpp, seq_t *seqp) struct file **fpp, seqc_t *seqp)
{ {
#ifdef CAPABILITIES #ifdef CAPABILITIES
const struct filedescent *fde; const struct filedescent *fde;
@ -2611,7 +2611,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
struct file *fp; struct file *fp;
u_int count; u_int count;
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_t seq; seqc_t seq;
cap_rights_t haverights; cap_rights_t haverights;
int error; int error;
#endif #endif
@ -2629,11 +2629,11 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
*/ */
for (;;) { for (;;) {
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq = seq_load(fd_seq(fdt, fd)); seq = seqc_read(fd_seqc(fdt, fd));
fde = &fdt->fdt_ofiles[fd]; fde = &fdt->fdt_ofiles[fd];
haverights = *cap_rights_fde_inline(fde); haverights = *cap_rights_fde_inline(fde);
fp = fde->fde_file; fp = fde->fde_file;
if (!seq_consistent(fd_seq(fdt, fd), seq)) if (!seqc_consistent(fd_seqc(fdt, fd), seq))
continue; continue;
#else #else
fp = fdt->fdt_ofiles[fd].fde_file; fp = fdt->fdt_ofiles[fd].fde_file;
@ -2664,7 +2664,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
goto retry; goto retry;
fdt = fdp->fd_files; fdt = fdp->fd_files;
#ifdef CAPABILITIES #ifdef CAPABILITIES
if (seq_consistent_nomb(fd_seq(fdt, fd), seq)) if (seqc_consistent_nomb(fd_seqc(fdt, fd), seq))
#else #else
if (fp == fdt->fdt_ofiles[fd].fde_file) if (fp == fdt->fdt_ofiles[fd].fde_file)
#endif #endif
@ -2695,7 +2695,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
*/ */
static __inline int static __inline int
_fget(struct thread *td, int fd, struct file **fpp, int flags, _fget(struct thread *td, int fd, struct file **fpp, int flags,
cap_rights_t *needrightsp, seq_t *seqp) cap_rights_t *needrightsp, seqc_t *seqp)
{ {
struct filedesc *fdp; struct filedesc *fdp;
struct file *fp; struct file *fp;
@ -2759,7 +2759,7 @@ fget_mmap(struct thread *td, int fd, cap_rights_t *rightsp, u_char *maxprotp,
*maxprotp = VM_PROT_ALL; *maxprotp = VM_PROT_ALL;
#else #else
struct filedesc *fdp = td->td_proc->p_fd; struct filedesc *fdp = td->td_proc->p_fd;
seq_t seq; seqc_t seq;
MPASS(cap_rights_is_set(rightsp, CAP_MMAP)); MPASS(cap_rights_is_set(rightsp, CAP_MMAP));
for (;;) { for (;;) {
@ -2802,7 +2802,7 @@ fget_fcntl(struct thread *td, int fd, cap_rights_t *rightsp, int needfcntl,
return (fget_unlocked(fdp, fd, rightsp, fpp, NULL)); return (fget_unlocked(fdp, fd, rightsp, fpp, NULL));
#else #else
int error; int error;
seq_t seq; seqc_t seq;
MPASS(cap_rights_is_set(rightsp, CAP_FCNTL)); MPASS(cap_rights_is_set(rightsp, CAP_FCNTL));
for (;;) { for (;;) {
@ -3046,13 +3046,13 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode,
oldfde = &fdp->fd_ofiles[dfd]; oldfde = &fdp->fd_ofiles[dfd];
ioctls = filecaps_copy_prep(&oldfde->fde_caps); ioctls = filecaps_copy_prep(&oldfde->fde_caps);
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_begin(&newfde->fde_seq); seqc_write_begin(&newfde->fde_seqc);
#endif #endif
memcpy(newfde, oldfde, fde_change_size); memcpy(newfde, oldfde, fde_change_size);
filecaps_copy_finish(&oldfde->fde_caps, &newfde->fde_caps, filecaps_copy_finish(&oldfde->fde_caps, &newfde->fde_caps,
ioctls); ioctls);
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_end(&newfde->fde_seq); seqc_write_end(&newfde->fde_seqc);
#endif #endif
break; break;
case ENXIO: case ENXIO:
@ -3062,13 +3062,13 @@ dupfdopen(struct thread *td, struct filedesc *fdp, int dfd, int mode,
newfde = &fdp->fd_ofiles[indx]; newfde = &fdp->fd_ofiles[indx];
oldfde = &fdp->fd_ofiles[dfd]; oldfde = &fdp->fd_ofiles[dfd];
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_begin(&newfde->fde_seq); seqc_write_begin(&newfde->fde_seqc);
#endif #endif
memcpy(newfde, oldfde, fde_change_size); memcpy(newfde, oldfde, fde_change_size);
oldfde->fde_file = NULL; oldfde->fde_file = NULL;
fdunused(fdp, dfd); fdunused(fdp, dfd);
#ifdef CAPABILITIES #ifdef CAPABILITIES
seq_write_end(&newfde->fde_seq); seqc_write_end(&newfde->fde_seqc);
#endif #endif
break; break;
} }

View File

@ -40,7 +40,7 @@
#include <sys/event.h> #include <sys/event.h>
#include <sys/lock.h> #include <sys/lock.h>
#include <sys/priority.h> #include <sys/priority.h>
#include <sys/seq.h> #include <sys/seqc.h>
#include <sys/sx.h> #include <sys/sx.h>
#include <machine/_limits.h> #include <machine/_limits.h>
@ -56,19 +56,19 @@ struct filedescent {
struct file *fde_file; /* file structure for open file */ struct file *fde_file; /* file structure for open file */
struct filecaps fde_caps; /* per-descriptor rights */ struct filecaps fde_caps; /* per-descriptor rights */
uint8_t fde_flags; /* per-process open file flags */ uint8_t fde_flags; /* per-process open file flags */
seq_t fde_seq; /* keep file and caps in sync */ seqc_t fde_seqc; /* keep file and caps in sync */
}; };
#define fde_rights fde_caps.fc_rights #define fde_rights fde_caps.fc_rights
#define fde_fcntls fde_caps.fc_fcntls #define fde_fcntls fde_caps.fc_fcntls
#define fde_ioctls fde_caps.fc_ioctls #define fde_ioctls fde_caps.fc_ioctls
#define fde_nioctls fde_caps.fc_nioctls #define fde_nioctls fde_caps.fc_nioctls
#define fde_change_size (offsetof(struct filedescent, fde_seq)) #define fde_change_size (offsetof(struct filedescent, fde_seqc))
struct fdescenttbl { struct fdescenttbl {
int fdt_nfiles; /* number of open files allocated */ int fdt_nfiles; /* number of open files allocated */
struct filedescent fdt_ofiles[0]; /* open files */ struct filedescent fdt_ofiles[0]; /* open files */
}; };
#define fd_seq(fdt, fd) (&(fdt)->fdt_ofiles[(fd)].fde_seq) #define fd_seqc(fdt, fd) (&(fdt)->fdt_ofiles[(fd)].fde_seqc)
/* /*
* This structure is used for the management of descriptors. It may be * This structure is used for the management of descriptors. It may be
@ -205,7 +205,7 @@ int fget_cap(struct thread *td, int fd, cap_rights_t *needrightsp,
/* Return a referenced file from an unlocked descriptor. */ /* Return a referenced file from an unlocked descriptor. */
int fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp, int fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
struct file **fpp, seq_t *seqp); struct file **fpp, seqc_t *seqp);
/* Requires a FILEDESC_{S,X}LOCK held and returns without a ref. */ /* Requires a FILEDESC_{S,X}LOCK held and returns without a ref. */
static __inline struct file * static __inline struct file *
@ -239,10 +239,10 @@ fdeget_locked(struct filedesc *fdp, int fd)
#ifdef CAPABILITIES #ifdef CAPABILITIES
static __inline bool static __inline bool
fd_modified(struct filedesc *fdp, int fd, seq_t seq) fd_modified(struct filedesc *fdp, int fd, seqc_t seqc)
{ {
return (!seq_consistent(fd_seq(fdp->fd_files, fd), seq)); return (!seqc_consistent(fd_seqc(fdp->fd_files, fd), seqc));
} }
#endif #endif

View File

@ -25,8 +25,8 @@
* $FreeBSD$ * $FreeBSD$
*/ */
#ifndef _SYS_SEQ_H_ #ifndef _SYS_SEQC_H_
#define _SYS_SEQ_H_ #define _SYS_SEQC_H_
#ifdef _KERNEL #ifdef _KERNEL
#include <sys/systm.h> #include <sys/systm.h>
@ -34,19 +34,19 @@
#include <sys/types.h> #include <sys/types.h>
/* /*
* seq_t may be included in structs visible to userspace * seqc_t may be included in structs visible to userspace
*/ */
typedef uint32_t seq_t; typedef uint32_t seqc_t;
#ifdef _KERNEL #ifdef _KERNEL
/* /*
* seq allows readers and writers to work with a consistent snapshot. Modifying * seqc allows readers and writers to work with a consistent snapshot. Modifying
* operations must be enclosed within a transaction delineated by * operations must be enclosed within a transaction delineated by
* seq_write_beg/seq_write_end. The trick works by having the writer increment * seqc_write_beg/seqc_write_end. The trick works by having the writer increment
* the sequence number twice, at the beginning and end of the transaction. * the seqcuence number twice, at the beginning and end of the transaction.
* The reader detects that the sequence number has not changed between its start * The reader detects that the seqcuence number has not changed between its start
* and end, and that the sequence number is even, to validate consistency. * and end, and that the seqcuence number is even, to validate consistency.
* *
* Some fencing (both hard fencing and compiler barriers) may be needed, * Some fencing (both hard fencing and compiler barriers) may be needed,
* depending on the cpu. Modern AMD cpus provide strong enough guarantees to not * depending on the cpu. Modern AMD cpus provide strong enough guarantees to not
@ -56,21 +56,21 @@ typedef uint32_t seq_t;
* *
* writers: * writers:
* lock_exclusive(&obj->lock); * lock_exclusive(&obj->lock);
* seq_write_begin(&obj->seq); * seqc_write_begin(&obj->seqc);
* obj->var1 = ...; * obj->var1 = ...;
* obj->var2 = ...; * obj->var2 = ...;
* seq_write_end(&obj->seq); * seqc_write_end(&obj->seqc);
* unlock_exclusive(&obj->lock); * unlock_exclusive(&obj->lock);
* *
* readers: * readers:
* int var1, var2; * int var1, var2;
* seq_t seq; * seqc_t seqc;
* *
* for (;;) { * for (;;) {
* seq = seq_read(&obj->seq); * seqc = seqc_read(&obj->seqc);
* var1 = obj->var1; * var1 = obj->var1;
* var2 = obj->var2; * var2 = obj->var2;
* if (seq_consistent(&obj->seq, seq)) * if (seqc_consistent(&obj->seqc, seqc))
* break; * break;
* } * }
* ..... * .....
@ -95,39 +95,39 @@ typedef uint32_t seq_t;
#include <machine/cpu.h> #include <machine/cpu.h>
static __inline bool static __inline bool
seq_in_modify(seq_t seqp) seqc_in_modify(seqc_t seqcp)
{ {
return (seqp & 1); return (seqcp & 1);
} }
static __inline void static __inline void
seq_write_begin(seq_t *seqp) seqc_write_begin(seqc_t *seqcp)
{ {
critical_enter(); critical_enter();
MPASS(!seq_in_modify(*seqp)); MPASS(!seqc_in_modify(*seqcp));
*seqp += 1; *seqcp += 1;
atomic_thread_fence_rel(); atomic_thread_fence_rel();
} }
static __inline void static __inline void
seq_write_end(seq_t *seqp) seqc_write_end(seqc_t *seqcp)
{ {
atomic_store_rel_int(seqp, *seqp + 1); atomic_store_rel_int(seqcp, *seqcp + 1);
MPASS(!seq_in_modify(*seqp)); MPASS(!seqc_in_modify(*seqcp));
critical_exit(); critical_exit();
} }
static __inline seq_t static __inline seqc_t
seq_load(const seq_t *seqp) seqc_read(const seqc_t *seqcp)
{ {
seq_t ret; seqc_t ret;
for (;;) { for (;;) {
ret = atomic_load_acq_int(__DECONST(seq_t *, seqp)); ret = atomic_load_acq_int(__DECONST(seqc_t *, seqcp));
if (seq_in_modify(ret)) { if (seqc_in_modify(ret)) {
cpu_spinwait(); cpu_spinwait();
continue; continue;
} }
@ -137,20 +137,20 @@ seq_load(const seq_t *seqp)
return (ret); return (ret);
} }
static __inline seq_t static __inline seqc_t
seq_consistent_nomb(const seq_t *seqp, seq_t oldseq) seqc_consistent_nomb(const seqc_t *seqcp, seqc_t oldseqc)
{ {
return (*seqp == oldseq); return (*seqcp == oldseqc);
} }
static __inline seq_t static __inline seqc_t
seq_consistent(const seq_t *seqp, seq_t oldseq) seqc_consistent(const seqc_t *seqcp, seqc_t oldseqc)
{ {
atomic_thread_fence_acq(); atomic_thread_fence_acq();
return (seq_consistent_nomb(seqp, oldseq)); return (seqc_consistent_nomb(seqcp, oldseqc));
} }
#endif /* _KERNEL */ #endif /* _KERNEL */
#endif /* _SYS_SEQ_H_ */ #endif /* _SYS_SEQC_H_ */