| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | #include <stdio.h> |
|---|
| 7 | #include <string.h> |
|---|
| 8 | #include <sys/types.h> |
|---|
| 9 | #include <sys/stat.h> |
|---|
| 10 | #include <unistd.h> |
|---|
| 11 | #include <fcntl.h> |
|---|
| 12 | #include <sys/time.h> |
|---|
| 13 | |
|---|
| 14 | #include "state-machine.h" |
|---|
| 15 | #include "client-state-machine.h" |
|---|
| 16 | #include "job-time-mgr.h" |
|---|
| 17 | |
|---|
| 18 | extern job_context_id pint_client_sm_context; |
|---|
| 19 | |
|---|
| 20 | %% |
|---|
| 21 | |
|---|
| 22 | machine pvfs2_sysdev_unexp_sm |
|---|
| 23 | { |
|---|
| 24 | state post |
|---|
| 25 | { |
|---|
| 26 | run sysdev_unexp_post; |
|---|
| 27 | default => cleanup; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | state cleanup |
|---|
| 31 | { |
|---|
| 32 | run sysdev_unexp_cleanup; |
|---|
| 33 | default => terminate; |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | %% |
|---|
| 38 | |
|---|
| 39 | /* sysdev_unexp_cleanup() |
|---|
| 40 | * |
|---|
| 41 | * cleans up any resources consumed by this state machine and ends |
|---|
| 42 | * execution of the machine |
|---|
| 43 | */ |
|---|
| 44 | static int sysdev_unexp_cleanup(struct PINT_smcb *smcb, job_status_s* js_p) |
|---|
| 45 | { |
|---|
| 46 | return SM_ACTION_TERMINATE; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | /* sysdev_unexp_post() |
|---|
| 50 | * |
|---|
| 51 | * posts an unexpected message job for the client |
|---|
| 52 | */ |
|---|
| 53 | static int sysdev_unexp_post(struct PINT_smcb *smcb, job_status_s* js_p) |
|---|
| 54 | { |
|---|
| 55 | struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); |
|---|
| 56 | PVFS_error ret; |
|---|
| 57 | job_id_t tmpid; |
|---|
| 58 | |
|---|
| 59 | memset(js_p, 0, sizeof(job_status_s)); |
|---|
| 60 | ret = job_dev_unexp(sm_p->u.sysdev_unexp.info, (void *)smcb, 0, js_p, |
|---|
| 61 | &tmpid, JOB_NO_IMMED_COMPLETE, pint_client_sm_context); |
|---|
| 62 | if (ret < 0) |
|---|
| 63 | { |
|---|
| 64 | PVFS_perror_gossip("PINT_sys_dev_unexp failed", ret); |
|---|
| 65 | return SM_ACTION_COMPLETE; |
|---|
| 66 | } |
|---|
| 67 | return SM_ACTION_DEFERRED; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | PVFS_error PINT_sys_dev_unexp( |
|---|
| 71 | struct PINT_dev_unexp_info *info, |
|---|
| 72 | job_status_s *jstat, |
|---|
| 73 | PVFS_sys_op_id *op_id, |
|---|
| 74 | void *user_ptr) |
|---|
| 75 | { |
|---|
| 76 | PVFS_error ret = -PVFS_EINVAL; |
|---|
| 77 | PINT_smcb *smcb = NULL; |
|---|
| 78 | PINT_client_sm *sm_p = NULL; |
|---|
| 79 | |
|---|
| 80 | gossip_debug(GOSSIP_CLIENT_DEBUG, "PINT_sys_dev_unexp\n"); |
|---|
| 81 | |
|---|
| 82 | /* we require more input args than the regular post method above */ |
|---|
| 83 | if (!info || !jstat || !op_id) |
|---|
| 84 | { |
|---|
| 85 | return -PVFS_EINVAL; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | ret = PINT_smcb_alloc(&smcb, PVFS_DEV_UNEXPECTED, |
|---|
| 89 | sizeof(struct PINT_client_sm), |
|---|
| 90 | client_op_state_get_machine, |
|---|
| 91 | client_state_machine_terminate, |
|---|
| 92 | pint_client_sm_context); |
|---|
| 93 | if (ret < 0) |
|---|
| 94 | { |
|---|
| 95 | gossip_lerr("Error: failed to allocate SMCB " |
|---|
| 96 | "of op type %x\n", PVFS_DEV_UNEXPECTED); |
|---|
| 97 | return ret; |
|---|
| 98 | } |
|---|
| 99 | sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); |
|---|
| 100 | sm_p->u.sysdev_unexp.info = info; |
|---|
| 101 | sm_p->cred_p = NULL; |
|---|
| 102 | |
|---|
| 103 | ret = PINT_client_state_machine_post(smcb, op_id, user_ptr); |
|---|
| 104 | |
|---|
| 105 | return ret; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /* |
|---|
| 109 | * Local variables: |
|---|
| 110 | * mode: c |
|---|
| 111 | * c-indent-level: 4 |
|---|
| 112 | * c-basic-offset: 4 |
|---|
| 113 | * End: |
|---|
| 114 | * |
|---|
| 115 | * vim: ft=c ts=8 sts=4 sw=4 expandtab |
|---|
| 116 | */ |
|---|