Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 286245
b: refs/heads/master
c: 3c0cf13
h: refs/heads/master
i:
  286243: a53e402
v: v3
  • Loading branch information
Matthew Wilcox committed Nov 4, 2011
1 parent 3fdd338 commit 2ec265b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: db5d0c198d673b6a932b449d4db95a2ad50c755e
refs/heads/master: 3c0cf138d7789feb3f335f6f1d24ad8fc8b3a23f
33 changes: 27 additions & 6 deletions trunk/drivers/block/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ static int alloc_cmdid_killable(struct nvme_queue *nvmeq, void *ctx,
}

/* If you need more than four handlers, you'll need to change how
* alloc_cmdid and nvme_process_cq work
* alloc_cmdid and nvme_process_cq work. Also, aborted commands take
* the sync_completion path (if they complete), so don't put anything
* else in slot zero.
*/
enum {
sync_completion_id = 0,
Expand All @@ -172,6 +174,11 @@ static unsigned long free_cmdid(struct nvme_queue *nvmeq, int cmdid)
return data;
}

static void clear_cmdid_data(struct nvme_queue *nvmeq, int cmdid)
{
nvmeq->cmdid_data[cmdid + BITS_TO_LONGS(nvmeq->q_depth)] = 0;
}

static struct nvme_queue *get_nvmeq(struct nvme_ns *ns)
{
int qid, cpu = get_cpu();
Expand Down Expand Up @@ -386,6 +393,8 @@ static void sync_completion(struct nvme_queue *nvmeq, void *ctx,
struct nvme_completion *cqe)
{
struct sync_cmd_info *cmdinfo = ctx;
if (!cmdinfo)
return; /* Command aborted */
cmdinfo->result = le32_to_cpup(&cqe->result);
cmdinfo->status = le16_to_cpup(&cqe->status) >> 1;
wake_up_process(cmdinfo->task);
Expand Down Expand Up @@ -446,28 +455,40 @@ static irqreturn_t nvme_irq(int irq, void *data)
return nvme_process_cq(data);
}

static void nvme_abort_command(struct nvme_queue *nvmeq, int cmdid)
{
spin_lock_irq(&nvmeq->q_lock);
clear_cmdid_data(nvmeq, cmdid);
spin_unlock_irq(&nvmeq->q_lock);
}

/*
* Returns 0 on success. If the result is negative, it's a Linux error code;
* if the result is positive, it's an NVM Express status code
*/
static int nvme_submit_sync_cmd(struct nvme_queue *q, struct nvme_command *cmd,
u32 *result)
static int nvme_submit_sync_cmd(struct nvme_queue *nvmeq,
struct nvme_command *cmd, u32 *result)
{
int cmdid;
struct sync_cmd_info cmdinfo;

cmdinfo.task = current;
cmdinfo.status = -EINTR;

cmdid = alloc_cmdid_killable(q, &cmdinfo, sync_completion_id);
cmdid = alloc_cmdid_killable(nvmeq, &cmdinfo, sync_completion_id);
if (cmdid < 0)
return cmdid;
cmd->common.command_id = cmdid;

set_current_state(TASK_UNINTERRUPTIBLE);
nvme_submit_cmd(q, cmd);
set_current_state(TASK_KILLABLE);
nvme_submit_cmd(nvmeq, cmd);
schedule();

if (cmdinfo.status == -EINTR) {
nvme_abort_command(nvmeq, cmdid);
return -EINTR;
}

if (result)
*result = cmdinfo.result;

Expand Down

0 comments on commit 2ec265b

Please sign in to comment.