Skip to content

Commit

Permalink
Shuffle files around more logically.
Browse files Browse the repository at this point in the history
  • Loading branch information
dacut committed Jun 14, 2016
1 parent 2e25a3c commit e8ff9d2
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/ublkdev-c++/Makefile → c++-client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


TARGETS = libublkdev.so ublkdev-s3
CPPFLAGS = -I. -I../../src
CPPFLAGS = -I. -I../kernel
CXXFLAGS = -std=c++11 -fPIC -Wall -g

LIB_SRCS = ublkdev.cc
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 25 additions & 20 deletions client/ublkdev-c++/s3.cc → c++-client/s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -948,29 +948,34 @@ void UBDS3Handler::run() {
// Event ready.
cerr << "Thread " << std::this_thread::get_id() << " processing a message" << endl;

try {
m_message.ubd_size = m_buffer_size;
m_ubd.getRequest(m_message);
}
catch (UBDError const &e) {
if (e.getError() == ENOMEM) {
// Resize the buffer
try {
cerr << "ENOMEM -- allocated " << m_buffer_size
<< " bytes but need " << m_message.ubd_size
<< " bytes" << endl;
resizeBuffer(m_message.ubd_size);
cerr << "Now have " << m_buffer_size << " bytes" << endl;
}
catch (bad_alloc &) {
cerr << "Thread " << std::this_thread::get_id()
<< " failed to allocate " << message.ubd_size
<< " bytes; exiting." << endl;
break;
while (true) {
try {
m_message.ubd_size = m_buffer_size;
m_ubd.getRequest(m_message);
break;
}
catch (UBDError const &e) {
if (e.getError() == ENOMEM) {
// Resize the buffer
try {
cerr << std::this_thread::get_id()
<< ": ENOMEM -- allocated " << m_buffer_size
<< " bytes but need " << m_message.ubd_size
<< " bytes" << endl;
resizeBuffer(m_message.ubd_size);
cerr << std::this_thread::get_id()
<< ": Now have " << m_buffer_size << " bytes" << endl;
}
catch (bad_alloc &) {
cerr << "Thread " << std::this_thread::get_id()
<< " failed to allocate " << message.ubd_size
<< " bytes; exiting." << endl;
break;
}
}
}
}

handleUBDRequest();
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/ublkdev.c → kernel/ublkdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ static long ubdctl_ioctl_getrequest(

// Wait for a message to become available *and* a tag slot to become
// available.
ubd_debug("About to enter spinlock to wait for a message");
spin_lock_irqsave(&dev->wait.lock, lock_flags);
if (wait_event_interruptible_locked(
dev->wait,
Expand All @@ -940,24 +941,40 @@ static long ubdctl_ioctl_getrequest(
spin_unlock_irqrestore(&dev->wait.lock, lock_flags);
return -ERESTARTSYS;
}
ubd_debug("Message and tag available");

msg.ubd_nsectors = blk_rq_sectors(req);
msg.ubd_first_sector = blk_rq_pos(req);

// Fill in the remaining details.
if ((req->cmd_flags & REQ_DISCARD) != 0) {
ubd_debug("Got a discard request (first_sector=%llu, nsectors=%llu)",
(long long unsigned) msg.ubd_first_sector,
(long long unsigned) msg.ubd_nsectors);
msg.ubd_msgtype = UBD_MSGTYPE_DISCARD;
msg.ubd_size = 0;
} else if ((req->cmd_flags & REQ_FLUSH) != 0) {
ubd_debug("Got a flush request (first_sector=%llu, nsectors=%llu)",
(long long unsigned) msg.ubd_first_sector,
(long long unsigned) msg.ubd_nsectors);
msg.ubd_msgtype = UBD_MSGTYPE_FLUSH;
msg.ubd_size = 0;
} else if (rq_data_dir(req) == READ) {
ubd_debug("Got a read request (first_sector=%llu, nsectors=%llu)",
(long long unsigned) msg.ubd_first_sector,
(long long unsigned) msg.ubd_nsectors);

msg.ubd_msgtype = UBD_MSGTYPE_READ;
msg.ubd_size = 0;
} else {
void __user *dest = msg.ubd_data;
uint32_t write_size = msg.ubd_nsectors << 9;

ubd_debug("Got a write request (first_sector=%llu, nsectors=%llu)",
(long long unsigned) msg.ubd_first_sector,
(long long unsigned) msg.ubd_nsectors);


BUG_ON(rq_data_dir(req) != WRITE);

if (write_size > msg.ubd_size) {
Expand Down Expand Up @@ -1005,6 +1022,8 @@ static long ubdctl_ioctl_getrequest(
}
}

ubd_debug("Allocated tag %u", tag);

BUG_ON(tag == max_pending_reply);
msg.ubd_tag = tag;
ACCESS_ONCE(dev->pending_reply[tag]) = req;
Expand All @@ -1027,6 +1046,7 @@ static long ubdctl_ioctl_getrequest(
}

spin_unlock_irqrestore(&dev->wait.lock, lock_flags);
ubd_debug("Left spinlock");

return 0;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e8ff9d2

Please sign in to comment.