Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linprocfs: Add support for proc/sysvipc/{msg,sem,shm} v2 #1232

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions share/man/man9/rman.9
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
.Nm rman_last_free_region ,
.Nm rman_release_resource ,
.Nm rman_reserve_resource ,
.Nm rman_reserve_resource_bound ,
.Nm rman_make_alignment_flags ,
.Nm rman_get_start ,
.Nm rman_get_end ,
Expand Down Expand Up @@ -90,11 +89,6 @@
.Fa "struct rman *rm" "rman_res_t start" "rman_res_t end" "rman_res_t count"
.Fa "u_int flags" "device_t dev"
.Fc
.Ft "struct resource *"
.Fo rman_reserve_resource_bound
.Fa "struct rman *rm" "rman_res_t start" "rman_res_t end" "rman_res_t count"
.Fa "rman_res_t bound" "u_int flags" "device_t dev"
.Fc
.Ft uint32_t
.Fn rman_make_alignment_flags "uint32_t size"
.Ft rman_res_t
Expand Down Expand Up @@ -266,7 +260,7 @@ and
are set to the bounds of the free region and zero is returned.
.Pp
The
.Fn rman_reserve_resource_bound
.Fn rman_reserve_resource
function is where the bulk of the
.Nm
logic is located.
Expand All @@ -279,7 +273,7 @@ The caller can specify the
and
.Fa end
of an acceptable range,
as well as a boundary restriction and required alignment,
required alignment,
and the code will attempt to find a free segment which fits.
The
.Fa start
Expand All @@ -296,31 +290,20 @@ The alignment requirement
.Pq if any
is specified in
.Fa flags .
The
.Fa bound
argument may be set to specify a boundary restriction such that an
allocated region may cross an address that is a multiple of the
boundary.
The
.Fa bound
argument must be a power of two.
It may be set to zero to specify no boundary restriction.
Often the
.Dv RF_ALIGNMENT_LOG2
macro is used to specify alignment to a power-of-2 size, or
.Fn rman_make_alignment_flags
can be used to compute the
.Fa flags
value at runtime.
A shared segment will be allocated if the
.Dv RF_SHAREABLE
flag is set, otherwise an exclusive segment will be allocated.
If this shared segment already exists, the caller has its device
added to the list of consumers.
.Pp
The
.Fn rman_reserve_resource
function is used to reserve resources within a previously established region.
It is a simplified interface to
.Fn rman_reserve_resource_bound
which passes 0 for the
.Fa bound
argument.
.Pp
The
.Fn rman_make_alignment_flags
function returns the flag mask corresponding to the desired alignment
.Fa size .
Expand Down
137 changes: 137 additions & 0 deletions sys/compat/linprocfs/linprocfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,134 @@
return (0);
}

/*
* Filler function for proc/sysvipc/msg
*/
static int
linprocfs_dosysvipc_msg(PFS_FILL_ARGS)
{
struct msqid_kernel *msqids;
size_t id, size;
int error;

sbuf_printf(sb,
"%10s %10s %4s %10s %10s %5s %5s %5s %5s %5s %5s %10s %10s %10s\n",
"key", "msqid", "perms", "cbytes", "qnum", "lspid", "lrpid",
"uid", "gid", "cuid", "cgid", "stime", "rtime", "ctime");

error = kern_get_msqids(curthread, &msqids, &size);
if (error != 0)
return (error);

for (id = 0; id < size; id++) {
if (msqids[id].u.msg_qbytes == 0)
continue;
sbuf_printf(sb,
"%10d %10lu %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %jd %jd %jd\n",
(int)msqids[id].u.msg_perm.key,
IXSEQ_TO_IPCID(id, msqids[id].u.msg_perm),
msqids[id].u.msg_perm.mode,
msqids[id].u.msg_cbytes,
msqids[id].u.msg_qnum,
msqids[id].u.msg_lspid,
msqids[id].u.msg_lrpid,
msqids[id].u.msg_perm.uid,
msqids[id].u.msg_perm.gid,
msqids[id].u.msg_perm.cuid,
msqids[id].u.msg_perm.cgid,
(intmax_t)msqids[id].u.msg_stime,
(intmax_t)msqids[id].u.msg_rtime,
(intmax_t)msqids[id].u.msg_ctime);
}

free(msqids, M_TEMP);
return (0);
}

/*
* Filler function for proc/sysvipc/sem
*/
static int
linprocfs_dosysvipc_sem(PFS_FILL_ARGS)
{
struct semid_kernel *semids;
size_t id, size;
int error;

sbuf_printf(sb, "%10s %10s %4s %10s %5s %5s %5s %5s %10s %10s\n",
"key", "semid", "perms", "nsems", "uid", "gid", "cuid", "cgid",
"otime", "ctime");

error = kern_get_sema(curthread, &semids, &size);
if (error != 0)
return (error);

for (id = 0; id < size; id++) {
if ((semids[id].u.sem_perm.mode & SEM_ALLOC) == 0)
continue;
sbuf_printf(sb,
"%10d %10lu %4o %10u %5u %5u %5u %5u %jd %jd\n",
(int)semids[id].u.sem_perm.key,
IXSEQ_TO_IPCID(id, semids[id].u.sem_perm),
semids[id].u.sem_perm.mode,
semids[id].u.sem_nsems,
semids[id].u.sem_perm.uid,
semids[id].u.sem_perm.gid,
semids[id].u.sem_perm.cuid,
semids[id].u.sem_perm.cgid,
(intmax_t)semids[id].u.sem_otime,
(intmax_t)semids[id].u.sem_ctime);
}

free(semids, M_TEMP);
return (0);
}

/*
* Filler function for proc/sysvipc/shm
*/
static int
linprocfs_dosysvipc_shm(PFS_FILL_ARGS)
{
struct shmid_kernel *shmids;
size_t id, size;
int error;

sbuf_printf(sb,
"%10s %10s %s %21s %5s %5s %5s %5s %5s %5s %5s %10s %10s %10s %21s %21s\n",
"key", "shmid", "perms", "size", "cpid", "lpid", "nattch", "uid",
"gid", "cuid", "cgid", "atime", "dtime", "ctime", "rss", "swap");

error = kern_get_shmsegs(curthread, &shmids, &size);
if (error != 0)
return (error);

for (id = 0; id < size; id++) {
if ((shmids[id].u.shm_perm.mode & SHMSEG_ALLOCATED) == 0)
continue;
sbuf_printf(sb,
"%10d %10lu %4o %21zu %5u %5u %5u %5u %5u %5u %5u %jd %jd %jd %21d %21d\n",
(int)shmids[id].u.shm_perm.key,
IXSEQ_TO_IPCID(id, shmids[id].u.shm_perm),
shmids[id].u.shm_perm.mode,
shmids[id].u.shm_segsz,
shmids[id].u.shm_cpid,
shmids[id].u.shm_lpid,
shmids[id].u.shm_nattch,
shmids[id].u.shm_perm.uid,
shmids[id].u.shm_perm.gid,
shmids[id].u.shm_perm.cuid,
shmids[id].u.shm_perm.cgid,
(intmax_t)shmids[id].u.shm_atime,
(intmax_t)shmids[id].u.shm_dtime,
(intmax_t)shmids[id].u.shm_ctime,
0, 0); /* XXX rss & swp are not supported */
}

free(shmids, M_TEMP);
return (0);
}

/*
* Constructor
*/
Expand Down Expand Up @@ -2241,9 +2369,18 @@
pfs_create_file(dir, "max_map_count", &linprocfs_domax_map_cnt,
NULL, NULL, NULL, PFS_RD);

/* /proc/sysvipc/... */
dir = pfs_create_dir(root, "sysvipc", NULL, NULL, NULL, 0);
pfs_create_file(dir, "msg", &linprocfs_dosysvipc_msg,
NULL, NULL, NULL, PFS_RD);
pfs_create_file(dir, "sem", &linprocfs_dosysvipc_sem,
NULL, NULL, NULL, PFS_RD);
pfs_create_file(dir, "shm", &linprocfs_dosysvipc_shm,
NULL, NULL, NULL, PFS_RD);

return (0);
}

Check warning on line 2383 in sys/compat/linprocfs/linprocfs.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
/*
* Destructor
*/
Expand Down
Loading
Loading