Skip to content

Commit fbf09b9

Browse files
committed
epoll: define EpollEvent structure per linux API
Signed-off-by: Tianhao Wang <[email protected]>
1 parent 53fe6b6 commit fbf09b9

File tree

8 files changed

+31
-50
lines changed

8 files changed

+31
-50
lines changed

qkernel/src/syscalls/sys_epoll.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn AddEpoll(
4949
fd: i32,
5050
flags: EntryFlags,
5151
mask: EventMask,
52-
userData: [i32; 2],
52+
userData: u64
5353
) -> Result<()> {
5454
// Get epoll from the file descriptor.
5555
let epollfile = task.GetFile(epfd)?;
@@ -83,7 +83,7 @@ pub fn UpdateEpoll(
8383
fd: i32,
8484
flags: EntryFlags,
8585
mask: EventMask,
86-
userData: [i32; 2],
86+
userData: u64
8787
) -> Result<()> {
8888
// Get epoll from the file descriptor.
8989
let epollfile = task.GetFile(epfd)?;
@@ -219,7 +219,7 @@ pub fn SysEpollCtl(task: &mut Task, args: &SyscallArguments) -> Result<i64> {
219219
// Capture the event state if needed.
220220
let mut flags = 0;
221221
let mut mask = 0;
222-
let mut data: [i32; 2] = [0, 0];
222+
let mut data: u64 = 0;
223223

224224
if op != LibcConst::EPOLL_CTL_DEL as i32 {
225225
let e: EpollEvent = task.CopyInObj(eventAddr)?;
@@ -233,8 +233,7 @@ pub fn SysEpollCtl(task: &mut Task, args: &SyscallArguments) -> Result<i64> {
233233
}
234234

235235
mask = EventMaskFromLinux(e.Events);
236-
data[0] = e.FD;
237-
data[1] = e.Pad;
236+
data = e.Data;
238237
}
239238

240239
// Perform the requested operations.

qkernel/src/syscalls/sys_poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub fn PollBlock(task: &Task, pfd: &mut [PollFd], timeout: i64) -> (Duration, Re
294294
let ep = EventPoll::default();
295295

296296
for (f, (mask, _)) in waits.iter() {
297-
match ep.AddEntry(task, f.clone(), 0, EventMaskFromLinux(*mask as u32), [0; 2]) {
297+
match ep.AddEntry(task, f.clone(), 0, EventMaskFromLinux(*mask as u32), 0) {
298298
Ok(()) => (),
299299
Err(e) => return (timeout, Err(e)),
300300
}

qlib/kernel/guestfdnotifier.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ pub fn Notify(fd: i32, mask: EventMask) {
3535
GlobalIOMgr().Notify(fd, mask);
3636
}
3737

38-
#[repr(C)]
39-
#[repr(packed)]
40-
#[derive(Default, Copy, Clone, Debug)]
41-
pub struct EpollEvent {
42-
pub Event: u32,
43-
pub U64: u64,
44-
}
45-
4638
impl IOMgr {
4739
pub fn VcpuWait(&self) -> u64 {
4840
let ret = HostSpace::VcpuWait();
@@ -62,8 +54,8 @@ impl IOMgr {
6254

6355
pub fn ProcessEvents(&self, events: &[EpollEvent]) {
6456
for e in events {
65-
let fd = e.U64 as i32;
66-
let event = e.Event as EventMask;
57+
let fd = e.Data as i32;
58+
let event = e.Events as EventMask;
6759
self.Notify(fd, event)
6860
}
6961
}

qlib/kernel/kernel/epoll/epoll.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Event {
5757

5858
// Data is an opaque 64-bit value provided by the caller when adding the
5959
// entry, and returned to the caller when the entry reports an event.
60-
pub Data: [i32; 2],
60+
pub Data: u64,
6161
}
6262

6363
#[cfg(target_arch = "aarch64")]
@@ -71,7 +71,7 @@ pub struct Event {
7171
_pad: i32,
7272
// Data is an opaque 64-bit value provided by the caller when adding the
7373
// entry, and returned to the caller when the entry reports an event.
74-
pub Data: [i32; 2],
74+
pub Data: u64,
7575
}
7676

7777
// An entry is always in one of the following lists:
@@ -227,8 +227,8 @@ impl EventPoll {
227227
#[cfg(target_arch = "aarch64")]
228228
events.Push(Event {
229229
Events: ready as u32,
230-
Data: entry.lock().userData,
231230
_pad: 0,
231+
Data: entry.lock().userData,
232232
});
233233
#[cfg(target_arch = "x86_64")]
234234
events.Push(Event {
@@ -311,7 +311,7 @@ impl EventPoll {
311311
file: File,
312312
flags: EntryFlags,
313313
mask: EventMask,
314-
data: [i32; 2],
314+
data: u64,
315315
) -> Result<()> {
316316
let id = file.UniqueId();
317317
let fops = file.FileOp.clone();
@@ -387,7 +387,7 @@ impl EventPoll {
387387
file: File,
388388
flags: EntryFlags,
389389
mask: EventMask,
390-
data: [i32; 2],
390+
data: u64,
391391
) -> Result<()> {
392392
let id = file.UniqueId();
393393
let files = self.files.lock();

qlib/kernel/kernel/epoll/epoll_entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct PollEntryInternal {
4141

4242
pub id: u64,
4343
pub file: FileWeak,
44-
pub userData: [i32; 2],
44+
pub userData: u64,
4545
pub waiter: WaitEntryWeak,
4646
pub mask: EventMask,
4747
pub flags: EntryFlags,

qlib/kernel/quring/uring_async.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,20 +1541,12 @@ impl PollHostEpollWait {
15411541
}
15421542
}
15431543

1544-
#[repr(C)]
1545-
#[repr(packed)]
1546-
#[derive(Debug, Default, Copy, Clone)]
1547-
pub struct EpollEvent1 {
1548-
pub Events: u32,
1549-
pub Data: u64,
1550-
}
1551-
15521544
#[derive(Clone, Debug, Copy)]
15531545
pub struct AsyncEpollCtl {
15541546
pub epollfd: i32,
15551547
pub fd: i32,
15561548
pub op: i32,
1557-
pub ev: EpollEvent1,
1549+
pub ev: EpollEvent,
15581550
}
15591551

15601552
impl AsyncOpsTrait for AsyncEpollCtl {
@@ -1571,10 +1563,7 @@ impl AsyncEpollCtl {
15711563
epollfd: epollfd,
15721564
fd: fd,
15731565
op: op,
1574-
ev: EpollEvent1 {
1575-
Events: mask,
1576-
Data: fd as u64,
1577-
},
1566+
ev: EpollEvent::new(mask, fd as u64)
15781567
};
15791568
}
15801569
}

qlib/linux_def.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,27 @@ pub struct LibcSysinfo {
264264
#[derive(Debug, Default, Copy, Clone)]
265265
pub struct EpollEvent {
266266
pub Events: u32,
267-
pub FD: i32,
268-
pub Pad: i32,
267+
pub Data: u64,
269268
}
270269

271270
#[cfg(target_arch = "aarch64")]
272271
#[repr(C)]
273272
#[derive(Debug, Default, Copy, Clone)]
274273
pub struct EpollEvent {
275274
pub Events: u32,
276-
pub _pad: i32,
277-
pub FD: i32,
278-
pub Pad: i32,
275+
_pad: i32,
276+
pub Data: u64,
277+
}
278+
279+
impl EpollEvent {
280+
#[cfg(target_arch = "x86_64")]
281+
pub fn new(events: u32, data: u64) -> Self {
282+
return Self {Events:events, Data:data}
283+
}
284+
#[cfg(target_arch = "aarch64")]
285+
pub fn new(events: u32, data: u64) -> Self {
286+
return Self {Events:events, _pad: 0, Data:data}
287+
}
279288
}
280289

281290
pub struct MRemapType {}

qvisor/src/vmspace/hostfdnotifier.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ use super::super::qlib::linux_def::*;
2121
//use super::super::qlib::qmsg::input::*;
2222
//use super::super::SHARE_SPACE;
2323

24-
#[repr(C)]
25-
#[repr(packed)]
26-
#[derive(Default, Copy, Clone, Debug)]
27-
pub struct EpollEvent {
28-
pub Event: u32,
29-
pub U64: u64,
30-
}
31-
3224
pub struct HostFdNotifier {
3325
//main epoll fd
3426
pub epollfd: i32,
@@ -93,8 +85,8 @@ impl HostFdNotifier {
9385

9486
if nfds > 0 {
9587
for e in &events[0..nfds as usize] {
96-
let fd = e.U64 as i32;
97-
let event = e.Event as EventMask;
88+
let fd = e.Data as i32;
89+
let event = e.Events as EventMask;
9890
Self::FdNotify(fd, event);
9991
}
10092
}

0 commit comments

Comments
 (0)