Changeset 9f0a68c in rtems


Ignore:
Timestamp:
Oct 31, 2012, 10:54:39 AM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
eb93595
Parents:
20e1e769
git-author:
Sebastian Huber <sebastian.huber@…> (10/31/12 10:54:39)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/02/12 08:40:58)
Message:

libblock: Block device transfer request API change

Add and use rtems_blkdev_request_done(). Block device transfer requests
must signal the completion status now with rtems_blkdev_request_done().
The return value of the block device IO control will be ignored for
transfer requests.

The first parameter of rtems_blkdev_request_cb is now the transfer
request structure.

Renamed rtems_blkdev_request::req_done to rtems_blkdev_request::done to
break third party drivers at compile time, otherwise this API change
would result in runtime errors.

Files:
19 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/gp32/smc/smc.c

    r20e1e769 r9f0a68c  
    545545static int smc_write(rtems_blkdev_request *req)
    546546{
    547         req->req_done(req->done_arg, RTEMS_SUCCESSFUL);
     547        rtems_blkdev_request_done(req, RTEMS_SUCCESSFUL);
    548548        return 0;
    549549}
     
    574574        remains -= count;
    575575    }
    576     req->req_done(req->done_arg, RTEMS_SUCCESSFUL);
     576    rtems_blkdev_request_done(req, RTEMS_SUCCESSFUL);
    577577    return 0;
    578578}
  • c/src/lib/libbsp/lm32/shared/milkymist_memcard/memcard.c

    r20e1e769 r9f0a68c  
    198198  }
    199199
    200   r->req_done(r->done_arg, RTEMS_SUCCESSFUL);
     200  rtems_blkdev_request_done(r, RTEMS_SUCCESSFUL);
    201201
    202202  return 0;
     
    205205static int memcard_disk_block_write(rtems_blkdev_request *r)
    206206{
    207   return -RTEMS_IO_ERROR;
     207  rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
     208
     209  return 0;
    208210}
    209211
  • c/src/libchip/i2c/spi-sd-card.c

    r20e1e769 r9f0a68c  
    11181118
    11191119        /* Done */
    1120         r->req_done( r->done_arg, RTEMS_SUCCESSFUL);
     1120        rtems_blkdev_request_done( r, RTEMS_SUCCESSFUL);
    11211121
    11221122        return 0;
     
    11331133
    11341134        /* Done */
    1135         r->req_done( r->done_arg, RTEMS_IO_ERROR);
    1136 
    1137         return rv;
     1135        rtems_blkdev_request_done( r, RTEMS_IO_ERROR);
     1136
     1137        return 0;
    11381138}
    11391139
     
    12071207
    12081208        /* Done */
    1209         r->req_done( r->done_arg, RTEMS_SUCCESSFUL);
     1209        rtems_blkdev_request_done( r, RTEMS_SUCCESSFUL);
    12101210
    12111211        return 0;
     
    12261226
    12271227        /* Done */
    1228         r->req_done( r->done_arg, RTEMS_IO_ERROR);
    1229 
    1230         return rv;
     1228        rtems_blkdev_request_done( r, RTEMS_IO_ERROR);
     1229
     1230        return 0;
    12311231}
    12321232
  • c/src/libchip/ide/ata.c

    r20e1e769 r9f0a68c  
    186186    if (areq == NULL)
    187187    {
    188         return RTEMS_NO_MEMORY;
     188        rtems_blkdev_request_done(req, RTEMS_NO_MEMORY);
     189        return RTEMS_SUCCESSFUL;
    189190    }
    190191
  • c/src/libchip/ide/ata_internal.h

    r20e1e769 r9f0a68c  
    219219#define ATA_EXEC_CALLBACK(areq, status) \
    220220    do {\
    221         if (((areq)->breq != NULL) && ((areq)->breq->req_done != NULL)) \
    222             (areq)->breq->req_done((areq)->breq->done_arg, status); \
     221        if ((areq)->breq != NULL) \
     222            rtems_blkdev_request_done((areq)->breq, status); \
    223223    } while (0)
    224224
  • cpukit/libblock/include/rtems/blkdev.h

    r20e1e769 r9f0a68c  
    5454} rtems_blkdev_request_op;
    5555
     56struct rtems_blkdev_request;
     57
    5658/**
    5759 * @brief Block device request done callback function type.
    58  *
    59  * The first parameter @a arg must be the argument provided by the block device
    60  * request structure @ref rtems_blkdev_request.
    61  *
    62  * The second parameter @a status should contain the status of the operation:
    63  *  - @c RTEMS_SUCCESSFUL Operation was successful.
    64  *  - @c RTEMS_IO_ERROR Some sort of input or output error.
    65  *  - @c RTEMS_UNSATISFIED Media no more present.
    66  */
    67 typedef void (*rtems_blkdev_request_cb)(void *arg, rtems_status_code status);
     60 */
     61typedef void (*rtems_blkdev_request_cb)(
     62  struct rtems_blkdev_request *req,
     63  rtems_status_code status
     64);
    6865
    6966/**
     
    9390
    9491/**
    95  * The block device request structure is used to read or write a number of
    96  * blocks from or to the device.
    97  *
    98  * TODO: The use of these req blocks is not a great design. The req is a
    99  *       struct with a single 'bufs' declared in the req struct and the
    100  *       others are added in the outer level struct. This relies on the
    101  *       structs joining as a single array and that assumes the compiler
    102  *       packs the structs. Why not just place on a list ? The BD has a
    103  *       node that can be used.
     92 * @brief The block device transfer request is used to read or write a number
     93 * of blocks from or to the device.
     94 *
     95 * Transfer requests are issued to the disk device driver with the
     96 * @ref RTEMS_BLKIO_REQUEST IO control.  The transfer request completion status
     97 * must be signalled with rtems_blkdev_request_done().  This function must be
     98 * called exactly once per request.  The return value of the IO control will be
     99 * ignored for transfer requests.
     100 *
     101 * @see rtems_blkdev_create().
    104102 */
    105103typedef struct rtems_blkdev_request {
     
    112110   * Request done callback function.
    113111   */
    114   rtems_blkdev_request_cb req_done;
     112  rtems_blkdev_request_cb done;
    115113
    116114  /**
     
    133131   */
    134132  rtems_id io_task;
     133
     134  /*
     135   * TODO: The use of these req blocks is not a great design. The req is a
     136   *       struct with a single 'bufs' declared in the req struct and the
     137   *       others are added in the outer level struct. This relies on the
     138   *       structs joining as a single array and that assumes the compiler
     139   *       packs the structs. Why not just place on a list ? The BD has a
     140   *       node that can be used.
     141   */
    135142
    136143  /**
     
    139146  rtems_blkdev_sg_buffer bufs[0];
    140147} rtems_blkdev_request;
     148
     149/**
     150 * @brief Signals transfer request completion status.
     151 *
     152 * This function must be called exactly once per request.
     153 *
     154 * @param[in,out] req The transfer request.
     155 * @param[in] status The status of the operation should be
     156 *  - @c RTEMS_SUCCESSFUL, if the operation was successful,
     157 *  - @c RTEMS_IO_ERROR, if some sort of input or output error occured, or
     158 *  - @c RTEMS_UNSATISFIED, if media is no more present.
     159 */
     160static inline void rtems_blkdev_request_done(
     161  rtems_blkdev_request *req,
     162  rtems_status_code status
     163)
     164{
     165  (*req->done)(req, status);
     166}
    141167
    142168/**
     
    342368 * @retval RTEMS_NO_MEMORY Not enough memory.
    343369 * @retval RTEMS_UNSATISFIED Cannot create generic device node.
     370 *
     371 * @see rtems_blkdev_create_partition() and rtems_blkdev_request.
    344372 */
    345373rtems_status_code rtems_blkdev_create(
     
    371399 * @retval RTEMS_NO_MEMORY Not enough memory.
    372400 * @retval RTEMS_UNSATISFIED Cannot create generic device node.
     401 *
     402 * @see rtems_blkdev_create().
    373403 */
    374404rtems_status_code rtems_blkdev_create_partition(
  • cpukit/libblock/src/bdbuf.c

    r20e1e769 r9f0a68c  
    18721872 */
    18731873static void
    1874 rtems_bdbuf_transfer_done (void* arg, rtems_status_code status)
    1875 {
    1876   rtems_blkdev_request* req = (rtems_blkdev_request*) arg;
    1877 
     1874rtems_bdbuf_transfer_done (rtems_blkdev_request* req, rtems_status_code status)
     1875{
    18781876  req->status = status;
    18791877
     
    18871885{
    18881886  rtems_status_code sc = RTEMS_SUCCESSFUL;
    1889   int result = 0;
    18901887  uint32_t transfer_index = 0;
    18911888  bool wake_transfer_waiters = false;
     
    18951892    rtems_bdbuf_unlock_cache ();
    18961893
    1897   result = dd->ioctl (dd->phys_dev, RTEMS_BLKIO_REQUEST, req);
    1898 
    1899   if (result == 0)
    1900   {
    1901     rtems_bdbuf_wait_for_transient_event ();
    1902     sc = req->status;
    1903   }
    1904   else
    1905     sc = RTEMS_IO_ERROR;
     1894  /* The return value will be ignored for transfer requests */
     1895  dd->ioctl (dd->phys_dev, RTEMS_BLKIO_REQUEST, req);
     1896
     1897  /* Wait for transfer request completion */
     1898  rtems_bdbuf_wait_for_transient_event ();
     1899  sc = req->status;
    19061900
    19071901  rtems_bdbuf_lock_cache ();
     
    19781972
    19791973  req->req = RTEMS_BLKDEV_REQ_READ;
    1980   req->req_done = rtems_bdbuf_transfer_done;
    1981   req->done_arg = req;
     1974  req->done = rtems_bdbuf_transfer_done;
    19821975  req->io_task = rtems_task_self ();
    1983   req->status = RTEMS_RESOURCE_IN_USE;
    19841976  req->bufnum = 0;
    19851977
     
    26562648
    26572649  write_req->req = RTEMS_BLKDEV_REQ_WRITE;
    2658   write_req->req_done = rtems_bdbuf_transfer_done;
    2659   write_req->done_arg = write_req;
     2650  write_req->done = rtems_bdbuf_transfer_done;
    26602651  write_req->io_task = rtems_task_self ();
    26612652
  • cpukit/libblock/src/flashdisk.c

    r20e1e769 r9f0a68c  
    20872087  }
    20882088
    2089   req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
    2090   req->req_done (req->done_arg, req->status);
     2089  rtems_blkdev_request_done (req, ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL);
    20912090
    20922091  return 0;
     
    21232122  }
    21242123
    2125   req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
    2126   req->req_done (req->done_arg, req->status);
     2124  rtems_blkdev_request_done (req, ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL);
    21272125
    21282126  return 0;
  • cpukit/libblock/src/nvdisk.c

    r20e1e769 r9f0a68c  
    598598  }
    599599
    600   req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
    601   req->req_done (req->done_arg, req->status);
    602 
    603   return ret;
     600  rtems_blkdev_request_done (req, ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL);
     601
     602  return 0;
    604603}
    605604
     
    638637  }
    639638
    640   req->status = ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL;
    641   req->req_done (req->done_arg, req->status);
     639  rtems_blkdev_request_done (req, ret ? RTEMS_IO_ERROR : RTEMS_SUCCESSFUL);
    642640
    643641  return 0;
  • cpukit/libblock/src/ramdisk-driver.c

    r20e1e769 r9f0a68c  
    6868        memcpy(sg->buffer, from + (sg->block * rd->block_size), sg->length);
    6969    }
    70     req->status = RTEMS_SUCCESSFUL;
    71     req->req_done(req->done_arg, RTEMS_SUCCESSFUL);
     70    rtems_blkdev_request_done (req, RTEMS_SUCCESSFUL);
    7271    return 0;
    7372}
     
    9392        memcpy(to + (sg->block * rd->block_size), sg->buffer, sg->length);
    9493    }
    95     req->status = RTEMS_SUCCESSFUL;
    96     req->req_done(req->done_arg, RTEMS_SUCCESSFUL);
     94    rtems_blkdev_request_done (req, RTEMS_SUCCESSFUL);
    9795    return 0;
    9896}
  • testsuites/libtests/block05/init.c

    r20e1e769 r9f0a68c  
    380380      case RTEMS_BLKDEV_REQ_READ:
    381381      case RTEMS_BLKDEV_REQ_WRITE:
    382         r->req_done(r->done_arg, RTEMS_SUCCESSFUL);
     382        rtems_blkdev_request_done(r, RTEMS_SUCCESSFUL);
    383383        return 0;
    384384      default:
  • testsuites/libtests/block06/init.c

    r20e1e769 r9f0a68c  
    489489          case RTEMS_BLKDEV_REQ_READ:
    490490            if (!bdbuf_disk_ioctl_process (bdd, r))
    491               errno = EIO;
     491              rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
    492492            else
    493493            {
     
    512512              }
    513513
    514               r->req_done (r->done_arg, RTEMS_SUCCESSFUL);
     514              rtems_blkdev_request_done (r, RTEMS_SUCCESSFUL);
    515515            }
    516516            bdbuf_disk_ioctl_leave (bdd, r->bufnum);
     
    519519          case RTEMS_BLKDEV_REQ_WRITE:
    520520            if (!bdbuf_disk_ioctl_process (bdd, r))
    521               errno = EIO;
    522             r->req_done (r->done_arg, RTEMS_SUCCESSFUL);
     521              rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
     522            else
     523              rtems_blkdev_request_done(r, RTEMS_SUCCESSFUL);
    523524            bdbuf_disk_ioctl_leave (bdd, r->bufnum);
    524525            break;
  • testsuites/libtests/block08/test_disk.c

    r20e1e769 r9f0a68c  
    3333test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *argp)
    3434{
    35     rtems_status_code rc;
    36     bdbuf_test_msg    msg;
    37     size_t            msg_size;
     35    rtems_status_code     rc;
     36    bdbuf_test_msg        msg;
     37    size_t                msg_size;
     38    rtems_blkdev_request *r;
    3839
    3940    switch (req)
     
    4142        case RTEMS_BLKIO_REQUEST:
    4243        {
    43             rtems_blkdev_request   *r = argp;
    4444            rtems_blkdev_sg_buffer *sg;
    4545            unsigned int            i;
     46
     47            r = argp;
    4648
    4749            printk("DISK_DRV: %s ",
     
    7274    {
    7375        printf("Error while sending a message to Test task: %u\n", rc);
    74         return -1;
     76        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
     77        return 0;
    7578    }
    7679
     
    8285    {
    8386        printf("Error while reading a message from Test task: %u\n", rc);
    84         return rc;
     87        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
     88        return 0;
    8589    }
    8690    if (msg.type != BDBUF_TEST_MSG_TYPE_DRIVER_REPLY)
     
    8892        printf("Unexpected message comes to test disk driver: %d\n",
    8993               msg.type);
    90         return -1;
     94        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
     95        return 0;
    9196    }
    9297
    9398    if (msg.val.driver_reply.ret_val != 0)
    9499    {
    95         errno = msg.val.driver_reply.ret_errno;
     100        rtems_blkdev_request_done(r, RTEMS_IO_ERROR);
    96101    }
    97102    else
    98103    {
    99         rtems_blkdev_request *r = (rtems_blkdev_request *)argp;
    100 
    101         r->req_done(r->done_arg, msg.val.driver_reply.res_status);
     104        rtems_blkdev_request_done(r, msg.val.driver_reply.res_status);
    102105    }
    103106
    104     return msg.val.driver_reply.ret_val;
     107    return 0;
    105108}
    106109
  • testsuites/libtests/block09/init.c

    r20e1e769 r9f0a68c  
    6565      char *buf = sg->buffer;
    6666
    67       if (sg->length != 1) {
    68         return -1;
    69       }
    70 
    71       switch (r->req) {
    72         case RTEMS_BLKDEV_REQ_READ:
    73           switch (sg->block) {
    74             case BLOCK_READ_IO_ERROR:
    75               sc = RTEMS_IO_ERROR;
    76               break;
    77             case BLOCK_READ_UNSATISFIED:
    78               sc = RTEMS_UNSATISFIED;
    79               break;
    80             case BLOCK_READ_SUCCESSFUL:
    81             case BLOCK_WRITE_IO_ERROR:
    82               *buf = disk_data [sg->block];
    83               break;
    84             default:
    85               return -1;
    86           }
    87           break;
    88         case RTEMS_BLKDEV_REQ_WRITE:
    89           switch (sg->block) {
    90             case BLOCK_READ_IO_ERROR:
    91             case BLOCK_READ_UNSATISFIED:
    92             case BLOCK_READ_SUCCESSFUL:
    93               disk_data [sg->block] = *buf;
    94               break;
    95             case BLOCK_WRITE_IO_ERROR:
    96               sc = RTEMS_IO_ERROR;
    97               break;
    98             default:
    99               return -1;
    100           }
    101           break;
    102         default:
    103           return -1;
     67      if (sg->length == 1) {
     68        switch (r->req) {
     69          case RTEMS_BLKDEV_REQ_READ:
     70            switch (sg->block) {
     71              case BLOCK_READ_IO_ERROR:
     72                sc = RTEMS_IO_ERROR;
     73                break;
     74              case BLOCK_READ_UNSATISFIED:
     75                sc = RTEMS_UNSATISFIED;
     76                break;
     77              case BLOCK_READ_SUCCESSFUL:
     78              case BLOCK_WRITE_IO_ERROR:
     79                *buf = disk_data [sg->block];
     80                break;
     81              default:
     82                sc = RTEMS_IO_ERROR;
     83                break;
     84            }
     85            break;
     86          case RTEMS_BLKDEV_REQ_WRITE:
     87            switch (sg->block) {
     88              case BLOCK_READ_IO_ERROR:
     89              case BLOCK_READ_UNSATISFIED:
     90              case BLOCK_READ_SUCCESSFUL:
     91                disk_data [sg->block] = *buf;
     92                break;
     93              case BLOCK_WRITE_IO_ERROR:
     94                sc = RTEMS_IO_ERROR;
     95                break;
     96              default:
     97                sc = RTEMS_IO_ERROR;
     98                break;
     99            }
     100            break;
     101          default:
     102            sc = RTEMS_IO_ERROR;
     103            break;
     104        }
     105      } else {
     106        sc = RTEMS_IO_ERROR;
    104107      }
    105108    }
    106109
    107     r->req_done(r->done_arg, sc);
     110    rtems_blkdev_request_done(r, sc);
    108111
    109112    return 0;
  • testsuites/libtests/block10/init.c

    r20e1e769 r9f0a68c  
    106106    }
    107107
    108     r->req_done(r->done_arg, sc);
     108    rtems_blkdev_request_done(r, sc);
    109109
    110110    return 0;
  • testsuites/libtests/block12/init.c

    r20e1e769 r9f0a68c  
    5656    }
    5757
    58     breq->req_done(breq->done_arg, RTEMS_SUCCESSFUL);
     58    rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
    5959  } else {
    6060    errno = EINVAL;
  • testsuites/libtests/block13/init.c

    r20e1e769 r9f0a68c  
    127127    }
    128128
    129     (*breq->req_done)(breq->done_arg, RTEMS_SUCCESSFUL);
     129    rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
    130130  } else {
    131131    errno = EINVAL;
  • testsuites/libtests/block14/init.c

    r20e1e769 r9f0a68c  
    106106    }
    107107
    108     (*breq->req_done)(breq->done_arg, sc);
     108    rtems_blkdev_request_done(breq, sc);
    109109  } else {
    110110    errno = EINVAL;
  • testsuites/libtests/block15/init.c

    r20e1e769 r9f0a68c  
    8585    }
    8686
    87     (*breq->req_done)(breq->done_arg, RTEMS_SUCCESSFUL);
     87    rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
    8888  } else if (req == RTEMS_BLKIO_CAPABILITIES) {
    8989    *(uint32_t *) arg = RTEMS_BLKDEV_CAP_MULTISECTOR_CONT;
Note: See TracChangeset for help on using the changeset viewer.