Skip to content

Commit

Permalink
Rename (#58)
Browse files Browse the repository at this point in the history
* Rename
  • Loading branch information
akiradeveloper authored May 18, 2024
1 parent a836cd8 commit 6167dfb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
33 changes: 16 additions & 17 deletions azbuse-kmod/src/azbuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,18 @@ static int azbuse_get_req(struct azbuse_device *azb, struct azbuse_xfr_hdr __use
spin_unlock_irq(&azb->azb_lock);

// Use the pointer address as the unique id of the request
xfr.azb_id = (__u64)req;
xfr.azb_command = xfr_command_from_cmd_flags(req->rq->cmd_flags);
xfr.azb_offset = blk_rq_pos(req->rq) << SECTOR_SHIFT;
xfr.azb_len = blk_rq_bytes(req->rq);
xfr.xfr_req_id = (__u64)req;
xfr.xfr_req_command = xfr_command_from_cmd_flags(req->rq->cmd_flags);
xfr.xfr_io_offset = blk_rq_pos(req->rq) << SECTOR_SHIFT;
xfr.xfr_io_len = blk_rq_bytes(req->rq);
rq_for_each_bvec(bvec, req->rq, iter) {
// physical address of the page
azb->azb_xfer[i].azb_address = (__u64)page_to_phys(bvec.bv_page);
azb->azb_xfer[i].pfn = (__u64)page_to_phys(bvec.bv_page) >> PAGE_SHIFT;
azb->azb_xfer[i].n_pages = ((bvec.bv_offset + bvec.bv_len) + (4096-1)) / 4096;
azb->azb_xfer[i].azb_offset = bvec.bv_offset;
azb->azb_xfer[i].azb_len = bvec.bv_len;
azb->azb_xfer[i].eff_offset = bvec.bv_offset;
azb->azb_xfer[i].eff_len = bvec.bv_len;
i++;
}
xfr.azb_vec_count = i;
xfr.xfr_vec_count = i;
azb->azb_xfer_count = i;
} else {
spin_unlock_irq(&azb->azb_lock);
Expand All @@ -207,8 +206,8 @@ static int azbuse_get_req(struct azbuse_device *azb, struct azbuse_xfr_hdr __use

if (copy_to_user(arg, &xfr, sizeof(xfr)))
return -EFAULT;
BUG_ON(xfr.azb_transfer_address == 0);
if (copy_to_user((__user void *) xfr.azb_transfer_address, azb->azb_xfer, xfr.azb_vec_count * sizeof(azb->azb_xfer[0])))
BUG_ON(xfr.xfr_transfer_address == 0);
if (copy_to_user((__user void *) xfr.xfr_transfer_address, azb->azb_xfer, xfr.xfr_vec_count * sizeof(azb->azb_xfer[0])))
return -EFAULT;

return 0;
Expand All @@ -223,19 +222,19 @@ static struct azb_req *azbuse_find_req(struct azbuse_device *azb, __u64 id)
// Complete a request
static int azbuse_put_req(struct azbuse_device *azb, struct azbuse_completion __user *arg)
{
struct azbuse_completion xfr;
struct azbuse_completion cmplt;
struct azb_req *req = NULL;

if (!arg)
return -EINVAL;
if (!azb)
return -ENODEV;

if (copy_from_user(&xfr, arg, sizeof (struct azbuse_completion)))
if (copy_from_user(&cmplt, arg, sizeof (struct azbuse_completion)))
return -EFAULT;

req = azbuse_find_req(azb, xfr.azb_id);
blk_mq_end_request(req->rq, errno_to_blk_status(xfr.azb_errno));
req = azbuse_find_req(azb, cmplt.cmplt_req_id);
blk_mq_end_request(req->rq, errno_to_blk_status(cmplt.cmplt_err));
return 0;
}

Expand Down Expand Up @@ -303,7 +302,7 @@ static int azbusectl_mmap(struct file *filp, struct vm_area_struct *vma)

cur = vma->vm_start;
for (i=0; i<n; i++) {
unsigned long pfn = azb->azb_xfer[i].azb_address >> PAGE_SHIFT;
unsigned long pfn = azb->azb_xfer[i].pfn;
unsigned long len = azb->azb_xfer[i].n_pages << PAGE_SHIFT;
err = remap_pfn_range(vma, cur, pfn, len, vma->vm_page_prot);
if (err) {
Expand All @@ -315,7 +314,7 @@ static int azbusectl_mmap(struct file *filp, struct vm_area_struct *vma)

// Rollback on failure
for (i=0; i<err_i; i++) {
unsigned long pfn = azb->azb_xfer[i].azb_address >> PAGE_SHIFT;
unsigned long pfn = azb->azb_xfer[i].pfn;
unsigned long len = azb->azb_xfer[i].n_pages;
unmap_mapping_pages(vma->vm_file->f_mapping, pfn, len, 0);
}
Expand Down
30 changes: 15 additions & 15 deletions azbuse-kmod/src/azbuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ struct azbuse_info {
#define AZBUSE_CTL_REMOVE 0x4187
#define AZBUSE_CONNECT 0x4188

struct azbuse_vec {
__u64 azb_address;
__u32 n_pages;
__u32 azb_offset;
__u32 azb_len;
};

#define CMD_OP_UNKNOWN 0
#define CMD_OP_READ 1
#define CMD_OP_WRITE 2
Expand All @@ -56,17 +49,24 @@ struct azbuse_vec {
#define CMD_RAHEAD 1<<12

struct azbuse_xfr_hdr {
__u64 azb_id;
__u64 azb_offset;
__u64 azb_len;
__u32 azb_command;
__u32 azb_vec_count;
__u64 azb_transfer_address;
__u64 xfr_req_id;
__u32 xfr_req_command;
__u64 xfr_io_offset;
__u64 xfr_io_len;
__u32 xfr_vec_count;
__u64 xfr_transfer_address;
};

struct azbuse_vec {
__u64 pfn;
__u32 n_pages;
__u32 eff_offset;
__u32 eff_len;
};

struct azbuse_completion {
__u64 azb_id;
__u32 azb_errno;
__u64 cmplt_req_id;
__u32 cmplt_err;
};

#define AZBUSE_MAJOR 60
Expand Down
26 changes: 13 additions & 13 deletions azbuse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ pub struct AzbuseInfo {
#[derive(Default)]
pub struct AzbuseXfr {
id: u64,
offset: u64,
len: u64,
cmd_flags: u32,
io_offset: u64,
io_len: u64,
io_vec_count: u32,
io_vec_address: u64,
}

#[repr(C)]
#[derive(Default, Clone, Copy)]
struct AzbuseXfrIoVec {
address: u64,
pfn: u64,
n_pages: u32,
offset: u32,
len: u32,
eff_offset: u32,
eff_len: u32,
}

#[repr(C)]
Expand All @@ -80,15 +80,15 @@ nix::ioctl_write_int_bad!(azbuse_connect, AZBUSE_CONNECT);
pub struct IOVec {
vm_addr: usize,
vm_len: usize,
io_offset: usize,
io_len: usize,
eff_offset: usize,
eff_len: usize,
}
impl IOVec {
pub fn start(&self) -> *mut c_void {
unsafe { std::mem::transmute::<usize, &mut c_void>(self.vm_addr + self.io_offset) }
unsafe { std::mem::transmute::<usize, &mut c_void>(self.vm_addr + self.eff_offset) }
}
pub fn len(&self) -> usize {
self.io_len
self.eff_len
}
}
impl Drop for IOVec {
Expand Down Expand Up @@ -233,8 +233,8 @@ pub async fn run_on(config: Config, engine: impl StorageEngine) {
io_vecs.push(IOVec {
vm_addr: cur,
vm_len: map_len,
io_offset: io_vec.offset as usize,
io_len: io_vec.len as usize,
eff_offset: io_vec.eff_offset as usize,
eff_len: io_vec.eff_len as usize,
});
cur += map_len;
}
Expand All @@ -243,8 +243,8 @@ pub async fn run_on(config: Config, engine: impl StorageEngine) {
let req = Request {
cmd_flags,
io_vecs,
io_start: xfr.offset,
io_len: xfr.len,
io_start: xfr.io_offset,
io_len: xfr.io_len,
request_id: xfr.id,
fd,
};
Expand Down

0 comments on commit 6167dfb

Please # to comment.