Skip to content

Commit 4c08a9f

Browse files
blucarppt
authored andcommitted
liveupdate: add LIVEUPDATE_SESSION_GET_NAME ioctl
Userspace when requesting a session via the ioctl specifies a name and gets a FD, but then there is no ioctl to go back the other way and get the name given a LUO session FD. This is problematic especially when there is a userspace orchestrator that wants to check what FDs it is handling for clients without having to do manual string scraping of procfs, or without procfs at all. Add a ioctl to simply get the name from an FD. Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Link: https://lore.kernel.org/r/20260429212221.814107-4-luca.boccassi@gmail.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent dab2b4c commit 4c08a9f

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

include/uapi/linux/liveupdate.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum {
5959
LIVEUPDATE_CMD_SESSION_PRESERVE_FD = LIVEUPDATE_CMD_SESSION_BASE,
6060
LIVEUPDATE_CMD_SESSION_RETRIEVE_FD = 0x41,
6161
LIVEUPDATE_CMD_SESSION_FINISH = 0x42,
62+
LIVEUPDATE_CMD_SESSION_GET_NAME = 0x43,
6263
};
6364

6465
/**
@@ -213,4 +214,24 @@ struct liveupdate_session_finish {
213214
#define LIVEUPDATE_SESSION_FINISH \
214215
_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_FINISH)
215216

217+
/**
218+
* struct liveupdate_session_get_name - ioctl(LIVEUPDATE_SESSION_GET_NAME)
219+
* @size: Input; sizeof(struct liveupdate_session_get_name)
220+
* @reserved: Input; Must be zero. Reserved for future use.
221+
* @name: Output; A null-terminated string with the full session name.
222+
*
223+
* Retrieves the full name of the session associated with this file descriptor.
224+
* This is useful because the kernel may truncate the name shown in /proc.
225+
*
226+
* Return: 0 on success, negative error code on failure.
227+
*/
228+
struct liveupdate_session_get_name {
229+
__u32 size;
230+
__u32 reserved;
231+
__u8 name[LIVEUPDATE_SESSION_NAME_LENGTH];
232+
};
233+
234+
#define LIVEUPDATE_SESSION_GET_NAME \
235+
_IO(LIVEUPDATE_IOCTL_TYPE, LIVEUPDATE_CMD_SESSION_GET_NAME)
236+
216237
#endif /* _UAPI_LIVEUPDATE_H */

kernel/liveupdate/luo_session.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,24 @@ static int luo_session_finish(struct luo_session *session,
289289
return luo_ucmd_respond(ucmd, sizeof(*argp));
290290
}
291291

292+
static int luo_session_get_name(struct luo_session *session,
293+
struct luo_ucmd *ucmd)
294+
{
295+
struct liveupdate_session_get_name *argp = ucmd->cmd;
296+
297+
if (argp->reserved != 0)
298+
return -EINVAL;
299+
300+
strscpy((char *)argp->name, session->name, sizeof(argp->name));
301+
302+
return luo_ucmd_respond(ucmd, sizeof(*argp));
303+
}
304+
292305
union ucmd_buffer {
293306
struct liveupdate_session_finish finish;
294307
struct liveupdate_session_preserve_fd preserve;
295308
struct liveupdate_session_retrieve_fd retrieve;
309+
struct liveupdate_session_get_name get_name;
296310
};
297311

298312
struct luo_ioctl_op {
@@ -319,6 +333,8 @@ static const struct luo_ioctl_op luo_session_ioctl_ops[] = {
319333
struct liveupdate_session_preserve_fd, token),
320334
IOCTL_OP(LIVEUPDATE_SESSION_RETRIEVE_FD, luo_session_retrieve_fd,
321335
struct liveupdate_session_retrieve_fd, token),
336+
IOCTL_OP(LIVEUPDATE_SESSION_GET_NAME, luo_session_get_name,
337+
struct liveupdate_session_get_name, name),
322338
};
323339

324340
static long luo_session_ioctl(struct file *filep, unsigned int cmd,

0 commit comments

Comments
 (0)