Changeset 984a9ba in mainline for uspace/srv/vfs/vfs_ipc.c


Ignore:
Timestamp:
2018-07-05T09:34:09Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63d46341
Parents:
76f566d
Message:

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_ipc.c

    r76f566d r984a9ba  
    3535#include <vfs/canonify.h>
    3636
    37 static void vfs_in_clone(cap_call_handle_t req_handle, ipc_call_t *request)
    38 {
    39         int oldfd = IPC_GET_ARG1(*request);
    40         int newfd = IPC_GET_ARG2(*request);
    41         bool desc = IPC_GET_ARG3(*request);
     37static void vfs_in_clone(ipc_call_t *req)
     38{
     39        int oldfd = IPC_GET_ARG1(*req);
     40        int newfd = IPC_GET_ARG2(*req);
     41        bool desc = IPC_GET_ARG3(*req);
    4242
    4343        int outfd = -1;
    4444        errno_t rc = vfs_op_clone(oldfd, newfd, desc, &outfd);
    45         async_answer_1(req_handle, rc, outfd);
    46 }
    47 
    48 static void vfs_in_fsprobe(cap_call_handle_t req_handle, ipc_call_t *request)
    49 {
    50         service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request);
     45        async_answer_1(req, rc, outfd);
     46}
     47
     48static void vfs_in_fsprobe(ipc_call_t *req)
     49{
     50        service_id_t service_id = (service_id_t) IPC_GET_ARG1(*req);
    5151        char *fs_name = NULL;
    52         cap_call_handle_t chandle;
    5352        vfs_fs_probe_info_t info;
    54         size_t len;
    5553        errno_t rc;
    5654
     
    6260            FS_NAME_MAXLEN, 0, NULL);
    6361        if (rc != EOK) {
    64                 async_answer_0(req_handle, rc);
     62                async_answer_0(req, rc);
    6563                return;
    6664        }
    6765
    6866        rc = vfs_op_fsprobe(fs_name, service_id, &info);
    69         async_answer_0(req_handle, rc);
     67        async_answer_0(req, rc);
    7068        if (rc != EOK)
    7169                goto out;
    7270
    7371        /* Now we should get a read request */
    74         if (!async_data_read_receive(&chandle, &len))
     72        ipc_call_t call;
     73        size_t len;
     74        if (!async_data_read_receive(&call, &len))
    7575                goto out;
    7676
    7777        if (len > sizeof(info))
    7878                len = sizeof(info);
    79         (void) async_data_read_finalize(chandle, &info, len);
     79        (void) async_data_read_finalize(&call, &info, len);
    8080
    8181out:
     
    8383}
    8484
    85 static void vfs_in_fstypes(cap_call_handle_t req_handle, ipc_call_t *request)
    86 {
    87         cap_call_handle_t chandle;
    88         size_t len;
     85static void vfs_in_fstypes(ipc_call_t *req)
     86{
    8987        vfs_fstypes_t fstypes;
    9088        errno_t rc;
     
    9290        rc = vfs_get_fstypes(&fstypes);
    9391        if (rc != EOK) {
    94                 async_answer_0(req_handle, ENOMEM);
     92                async_answer_0(req, ENOMEM);
    9593                return;
    9694        }
    9795
    9896        /* Send size of the data */
    99         async_answer_1(req_handle, EOK, fstypes.size);
     97        async_answer_1(req, EOK, fstypes.size);
    10098
    10199        /* Now we should get a read request */
    102         if (!async_data_read_receive(&chandle, &len))
     100        ipc_call_t call;
     101        size_t len;
     102        if (!async_data_read_receive(&call, &len))
    103103                goto out;
    104104
    105105        if (len > fstypes.size)
    106106                len = fstypes.size;
    107         (void) async_data_read_finalize(chandle, fstypes.buf, len);
     107        (void) async_data_read_finalize(&call, fstypes.buf, len);
    108108
    109109out:
     
    111111}
    112112
    113 static void vfs_in_mount(cap_call_handle_t req_handle, ipc_call_t *request)
    114 {
    115         int mpfd = IPC_GET_ARG1(*request);
     113static void vfs_in_mount(ipc_call_t *req)
     114{
     115        int mpfd = IPC_GET_ARG1(*req);
    116116
    117117        /*
     
    120120         * in the request.
    121121         */
    122         service_id_t service_id = (service_id_t) IPC_GET_ARG2(*request);
    123 
    124         unsigned int flags = (unsigned int) IPC_GET_ARG3(*request);
    125         unsigned int instance = IPC_GET_ARG4(*request);
     122        service_id_t service_id = (service_id_t) IPC_GET_ARG2(*req);
     123
     124        unsigned int flags = (unsigned int) IPC_GET_ARG3(*req);
     125        unsigned int instance = IPC_GET_ARG4(*req);
    126126
    127127        char *opts = NULL;
     
    132132            MAX_MNTOPTS_LEN, 0, NULL);
    133133        if (rc != EOK) {
    134                 async_answer_0(req_handle, rc);
     134                async_answer_0(req, rc);
    135135                return;
    136136        }
     
    144144        if (rc != EOK) {
    145145                free(opts);
    146                 async_answer_0(req_handle, rc);
     146                async_answer_0(req, rc);
    147147                return;
    148148        }
     
    151151        rc = vfs_op_mount(mpfd, service_id, flags, instance, opts, fs_name,
    152152            &outfd);
    153         async_answer_1(req_handle, rc, outfd);
     153        async_answer_1(req, rc, outfd);
    154154
    155155        free(opts);
     
    157157}
    158158
    159 static void vfs_in_open(cap_call_handle_t req_handle, ipc_call_t *request)
    160 {
    161         int fd = IPC_GET_ARG1(*request);
    162         int mode = IPC_GET_ARG2(*request);
     159static void vfs_in_open(ipc_call_t *req)
     160{
     161        int fd = IPC_GET_ARG1(*req);
     162        int mode = IPC_GET_ARG2(*req);
    163163
    164164        errno_t rc = vfs_op_open(fd, mode);
    165         async_answer_0(req_handle, rc);
    166 }
    167 
    168 static void vfs_in_put(cap_call_handle_t req_handle, ipc_call_t *request)
    169 {
    170         int fd = IPC_GET_ARG1(*request);
     165        async_answer_0(req, rc);
     166}
     167
     168static void vfs_in_put(ipc_call_t *req)
     169{
     170        int fd = IPC_GET_ARG1(*req);
    171171        errno_t rc = vfs_op_put(fd);
    172         async_answer_0(req_handle, rc);
    173 }
    174 
    175 static void vfs_in_read(cap_call_handle_t req_handle, ipc_call_t *request)
    176 {
    177         int fd = IPC_GET_ARG1(*request);
    178         aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
    179             IPC_GET_ARG3(*request));
     172        async_answer_0(req, rc);
     173}
     174
     175static void vfs_in_read(ipc_call_t *req)
     176{
     177        int fd = IPC_GET_ARG1(*req);
     178        aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*req),
     179            IPC_GET_ARG3(*req));
    180180
    181181        size_t bytes = 0;
    182182        errno_t rc = vfs_op_read(fd, pos, &bytes);
    183         async_answer_1(req_handle, rc, bytes);
    184 }
    185 
    186 static void vfs_in_rename(cap_call_handle_t req_handle, ipc_call_t *request)
     183        async_answer_1(req, rc, bytes);
     184}
     185
     186static void vfs_in_rename(ipc_call_t *req)
    187187{
    188188        /* The common base directory. */
     
    192192        errno_t rc;
    193193
    194         basefd = IPC_GET_ARG1(*request);
     194        basefd = IPC_GET_ARG1(*req);
    195195
    196196        /* Retrieve the old path. */
     
    220220
    221221out:
    222         async_answer_0(req_handle, rc);
     222        async_answer_0(req, rc);
    223223
    224224        if (old)
     
    228228}
    229229
    230 static void vfs_in_resize(cap_call_handle_t req_handle, ipc_call_t *request)
    231 {
    232         int fd = IPC_GET_ARG1(*request);
    233         int64_t size = MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
     230static void vfs_in_resize(ipc_call_t *req)
     231{
     232        int fd = IPC_GET_ARG1(*req);
     233        int64_t size = MERGE_LOUP32(IPC_GET_ARG2(*req), IPC_GET_ARG3(*req));
    234234        errno_t rc = vfs_op_resize(fd, size);
    235         async_answer_0(req_handle, rc);
    236 }
    237 
    238 static void vfs_in_stat(cap_call_handle_t req_handle, ipc_call_t *request)
    239 {
    240         int fd = IPC_GET_ARG1(*request);
     235        async_answer_0(req, rc);
     236}
     237
     238static void vfs_in_stat(ipc_call_t *req)
     239{
     240        int fd = IPC_GET_ARG1(*req);
    241241        errno_t rc = vfs_op_stat(fd);
    242         async_answer_0(req_handle, rc);
    243 }
    244 
    245 static void vfs_in_statfs(cap_call_handle_t req_handle, ipc_call_t *request)
    246 {
    247         int fd = (int) IPC_GET_ARG1(*request);
     242        async_answer_0(req, rc);
     243}
     244
     245static void vfs_in_statfs(ipc_call_t *req)
     246{
     247        int fd = (int) IPC_GET_ARG1(*req);
    248248
    249249        errno_t rc = vfs_op_statfs(fd);
    250         async_answer_0(req_handle, rc);
    251 }
    252 
    253 static void vfs_in_sync(cap_call_handle_t req_handle, ipc_call_t *request)
    254 {
    255         int fd = IPC_GET_ARG1(*request);
     250        async_answer_0(req, rc);
     251}
     252
     253static void vfs_in_sync(ipc_call_t *req)
     254{
     255        int fd = IPC_GET_ARG1(*req);
    256256        errno_t rc = vfs_op_sync(fd);
    257         async_answer_0(req_handle, rc);
    258 }
    259 
    260 static void vfs_in_unlink(cap_call_handle_t req_handle, ipc_call_t *request)
    261 {
    262         int parentfd = IPC_GET_ARG1(*request);
    263         int expectfd = IPC_GET_ARG2(*request);
     257        async_answer_0(req, rc);
     258}
     259
     260static void vfs_in_unlink(ipc_call_t *req)
     261{
     262        int parentfd = IPC_GET_ARG1(*req);
     263        int expectfd = IPC_GET_ARG2(*req);
    264264
    265265        char *path;
     
    268268                rc = vfs_op_unlink(parentfd, expectfd, path);
    269269
    270         async_answer_0(req_handle, rc);
    271 }
    272 
    273 static void vfs_in_unmount(cap_call_handle_t req_handle, ipc_call_t *request)
    274 {
    275         int mpfd = IPC_GET_ARG1(*request);
     270        async_answer_0(req, rc);
     271}
     272
     273static void vfs_in_unmount(ipc_call_t *req)
     274{
     275        int mpfd = IPC_GET_ARG1(*req);
    276276        errno_t rc = vfs_op_unmount(mpfd);
    277         async_answer_0(req_handle, rc);
    278 }
    279 
    280 static void vfs_in_wait_handle(cap_call_handle_t req_handle, ipc_call_t *request)
    281 {
    282         bool high_fd = IPC_GET_ARG1(*request);
     277        async_answer_0(req, rc);
     278}
     279
     280static void vfs_in_wait_handle(ipc_call_t *req)
     281{
     282        bool high_fd = IPC_GET_ARG1(*req);
    283283        int fd = -1;
    284284        errno_t rc = vfs_op_wait_handle(high_fd, &fd);
    285         async_answer_1(req_handle, rc, fd);
    286 }
    287 
    288 static void vfs_in_walk(cap_call_handle_t req_handle, ipc_call_t *request)
     285        async_answer_1(req, rc, fd);
     286}
     287
     288static void vfs_in_walk(ipc_call_t *req)
    289289{
    290290        /*
     
    292292         * For defined flags, see <ipc/vfs.h>.
    293293         */
    294         int parentfd = IPC_GET_ARG1(*request);
    295         int flags = IPC_GET_ARG2(*request);
     294        int parentfd = IPC_GET_ARG1(*req);
     295        int flags = IPC_GET_ARG2(*req);
    296296
    297297        int fd = 0;
     
    302302                free(path);
    303303        }
    304         async_answer_1(req_handle, rc, fd);
    305 }
    306 
    307 static void vfs_in_write(cap_call_handle_t req_handle, ipc_call_t *request)
    308 {
    309         int fd = IPC_GET_ARG1(*request);
    310         aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
    311             IPC_GET_ARG3(*request));
     304        async_answer_1(req, rc, fd);
     305}
     306
     307static void vfs_in_write(ipc_call_t *req)
     308{
     309        int fd = IPC_GET_ARG1(*req);
     310        aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*req),
     311            IPC_GET_ARG3(*req));
    312312
    313313        size_t bytes = 0;
    314314        errno_t rc = vfs_op_write(fd, pos, &bytes);
    315         async_answer_1(req_handle, rc, bytes);
    316 }
    317 
    318 void vfs_connection(cap_call_handle_t icall_handle, ipc_call_t *icall, void *arg)
     315        async_answer_1(req, rc, bytes);
     316}
     317
     318void vfs_connection(ipc_call_t *icall, void *arg)
    319319{
    320320        bool cont = true;
     
    324324         * This call needs to be answered.
    325325         */
    326         async_answer_0(icall_handle, EOK);
     326        async_answer_0(icall, EOK);
    327327
    328328        while (cont) {
    329329                ipc_call_t call;
    330                 cap_call_handle_t chandle = async_get_call(&call);
     330                async_get_call(&call);
    331331
    332332                if (!IPC_GET_IMETHOD(call))
     
    335335                switch (IPC_GET_IMETHOD(call)) {
    336336                case VFS_IN_CLONE:
    337                         vfs_in_clone(chandle, &call);
     337                        vfs_in_clone(&call);
    338338                        break;
    339339                case VFS_IN_FSPROBE:
    340                         vfs_in_fsprobe(chandle, &call);
     340                        vfs_in_fsprobe(&call);
    341341                        break;
    342342                case VFS_IN_FSTYPES:
    343                         vfs_in_fstypes(chandle, &call);
     343                        vfs_in_fstypes(&call);
    344344                        break;
    345345                case VFS_IN_MOUNT:
    346                         vfs_in_mount(chandle, &call);
     346                        vfs_in_mount(&call);
    347347                        break;
    348348                case VFS_IN_OPEN:
    349                         vfs_in_open(chandle, &call);
     349                        vfs_in_open(&call);
    350350                        break;
    351351                case VFS_IN_PUT:
    352                         vfs_in_put(chandle, &call);
     352                        vfs_in_put(&call);
    353353                        break;
    354354                case VFS_IN_READ:
    355                         vfs_in_read(chandle, &call);
     355                        vfs_in_read(&call);
    356356                        break;
    357357                case VFS_IN_REGISTER:
    358                         vfs_register(chandle, &call);
     358                        vfs_register(&call);
    359359                        cont = false;
    360360                        break;
    361361                case VFS_IN_RENAME:
    362                         vfs_in_rename(chandle, &call);
     362                        vfs_in_rename(&call);
    363363                        break;
    364364                case VFS_IN_RESIZE:
    365                         vfs_in_resize(chandle, &call);
     365                        vfs_in_resize(&call);
    366366                        break;
    367367                case VFS_IN_STAT:
    368                         vfs_in_stat(chandle, &call);
     368                        vfs_in_stat(&call);
    369369                        break;
    370370                case VFS_IN_STATFS:
    371                         vfs_in_statfs(chandle, &call);
     371                        vfs_in_statfs(&call);
    372372                        break;
    373373                case VFS_IN_SYNC:
    374                         vfs_in_sync(chandle, &call);
     374                        vfs_in_sync(&call);
    375375                        break;
    376376                case VFS_IN_UNLINK:
    377                         vfs_in_unlink(chandle, &call);
     377                        vfs_in_unlink(&call);
    378378                        break;
    379379                case VFS_IN_UNMOUNT:
    380                         vfs_in_unmount(chandle, &call);
     380                        vfs_in_unmount(&call);
    381381                        break;
    382382                case VFS_IN_WAIT_HANDLE:
    383                         vfs_in_wait_handle(chandle, &call);
     383                        vfs_in_wait_handle(&call);
    384384                        break;
    385385                case VFS_IN_WALK:
    386                         vfs_in_walk(chandle, &call);
     386                        vfs_in_walk(&call);
    387387                        break;
    388388                case VFS_IN_WRITE:
    389                         vfs_in_write(chandle, &call);
     389                        vfs_in_write(&call);
    390390                        break;
    391391                default:
    392                         async_answer_0(chandle, ENOTSUP);
     392                        async_answer_0(&call, ENOTSUP);
    393393                        break;
    394394                }
Note: See TracChangeset for help on using the changeset viewer.