diff options
Diffstat (limited to 'xlators/cluster/ec/src/ec-inode-write.c')
-rw-r--r-- | xlators/cluster/ec/src/ec-inode-write.c | 510 |
1 files changed, 180 insertions, 330 deletions
diff --git a/xlators/cluster/ec/src/ec-inode-write.c b/xlators/cluster/ec/src/ec-inode-write.c index ff8e89e6a72..31ab53b86c7 100644 --- a/xlators/cluster/ec/src/ec-inode-write.c +++ b/xlators/cluster/ec/src/ec-inode-write.c @@ -141,20 +141,7 @@ ec_manager_xattr (ec_fop_data_t *fop, int32_t state) return EC_STATE_PREPARE_ANSWER; case EC_STATE_PREPARE_ANSWER: - cbk = fop->answer; - if (cbk) { - if (!ec_dict_combine (cbk, EC_COMBINE_XDATA)) { - if (cbk->op_ret >= 0) { - cbk->op_ret = -1; - cbk->op_errno = EIO; - } - } - - if (cbk->op_ret < 0) - ec_fop_set_error(fop, cbk->op_errno); - } else { - ec_fop_set_error(fop, EIO); - } + ec_fop_prepare_answer(fop, _gf_false); return EC_STATE_REPORT; @@ -193,7 +180,7 @@ ec_manager_xattr (ec_fop_data_t *fop, int32_t state) return EC_STATE_END; default: - gf_msg (fop->xl->name, GF_LOG_ERROR, 0, + gf_msg (fop->xl->name, GF_LOG_ERROR, EINVAL, EC_MSG_UNHANDLED_STATE, "Unhandled state %d for %s", state, ec_fop_name(fop->id)); @@ -209,7 +196,7 @@ ec_removexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, { ec_cbk_t callback = { .removexattr = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(REMOVEXATTR) %p", frame); @@ -221,27 +208,22 @@ ec_removexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, EC_FLAG_UPDATE_LOC_INODE, target, minimum, ec_wind_removexattr, ec_manager_xattr, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } - if (loc != NULL) - { - if (loc_copy(&fop->loc[0], loc) != 0) - { - gf_msg (this->name, GF_LOG_ERROR, 0, + if (loc != NULL) { + if (loc_copy(&fop->loc[0], loc) != 0) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_LOC_COPY_FAIL, "Failed to copy a location."); goto out; } } - if (name != NULL) - { + if (name != NULL) { fop->str[0] = gf_strdup(name); - if (fop->str[0] == NULL) - { + if (fop->str[0] == NULL) { gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_NO_MEMORY, "Failed to duplicate a string."); @@ -249,11 +231,9 @@ ec_removexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -299,7 +279,7 @@ ec_fremovexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, { ec_cbk_t callback = { .fremovexattr = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(FREMOVEXATTR) %p", frame); @@ -311,18 +291,15 @@ ec_fremovexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, EC_FLAG_UPDATE_FD_INODE, target, minimum, ec_wind_fremovexattr, ec_manager_xattr, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } fop->use_fd = 1; - if (fd != NULL) - { + if (fd != NULL) { fop->fd = fd_ref(fd); - if (fop->fd == NULL) - { + if (fop->fd == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_FILE_DESC_REF_FAIL, "Failed to reference a " @@ -331,11 +308,9 @@ ec_fremovexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, goto out; } } - if (name != NULL) - { + if (name != NULL) { fop->str[0] = gf_strdup(name); - if (fop->str[0] == NULL) - { + if (fop->str[0] == NULL) { gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_NO_MEMORY, "Failed to duplicate a string."); @@ -343,11 +318,9 @@ ec_fremovexattr (call_frame_t *frame, xlator_t *this, uintptr_t target, goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -412,20 +385,9 @@ int32_t ec_manager_setattr(ec_fop_data_t * fop, int32_t state) return EC_STATE_PREPARE_ANSWER; case EC_STATE_PREPARE_ANSWER: - cbk = fop->answer; - if (cbk != NULL) - { - if (!ec_dict_combine(cbk, EC_COMBINE_XDATA)) - { - if (cbk->op_ret >= 0) - { - cbk->op_ret = -1; - cbk->op_errno = EIO; - } - } - if (cbk->op_ret < 0) { - ec_fop_set_error(fop, cbk->op_errno); - } else if (cbk->iatt[0].ia_type == IA_IFREG) { + cbk = ec_fop_prepare_answer(fop, _gf_false); + if (cbk != NULL) { + if (cbk->iatt[0].ia_type == IA_IFREG) { ec_iatt_rebuild(fop->xl->private, cbk->iatt, 2, cbk->count); @@ -436,10 +398,6 @@ int32_t ec_manager_setattr(ec_fop_data_t * fop, int32_t state) cbk->iatt[1].ia_size = cbk->iatt[0].ia_size; } } - else - { - ec_fop_set_error(fop, EIO); - } return EC_STATE_REPORT; @@ -510,7 +468,7 @@ int32_t ec_manager_setattr(ec_fop_data_t * fop, int32_t state) return EC_STATE_END; default: - gf_msg (fop->xl->name, GF_LOG_ERROR, 0, + gf_msg (fop->xl->name, GF_LOG_ERROR, EINVAL, EC_MSG_UNHANDLED_STATE, "Unhandled state %d for %s", state, ec_fop_name(fop->id)); @@ -526,7 +484,7 @@ void ec_setattr(call_frame_t * frame, xlator_t * this, uintptr_t target, { ec_cbk_t callback = { .setattr = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(SETATTR) %p", frame); @@ -538,33 +496,27 @@ void ec_setattr(call_frame_t * frame, xlator_t * this, uintptr_t target, EC_FLAG_UPDATE_LOC_INODE, target, minimum, ec_wind_setattr, ec_manager_setattr, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } fop->int32 = valid; - if (loc != NULL) - { - if (loc_copy(&fop->loc[0], loc) != 0) - { - gf_msg (this->name, GF_LOG_ERROR, 0, + if (loc != NULL) { + if (loc_copy(&fop->loc[0], loc) != 0) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_LOC_COPY_FAIL, "Failed to copy a location."); goto out; } } - if (stbuf != NULL) - { + if (stbuf != NULL) { fop->iatt = *stbuf; } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -577,13 +529,10 @@ void ec_setattr(call_frame_t * frame, xlator_t * this, uintptr_t target, error = 0; out: - if (fop != NULL) - { + if (fop != NULL) { ec_manager(fop, error); - } - else - { - func(frame, NULL, this, -1, EIO, NULL, NULL, NULL); + } else { + func(frame, NULL, this, -1, error, NULL, NULL, NULL); } } @@ -613,7 +562,7 @@ void ec_fsetattr(call_frame_t * frame, xlator_t * this, uintptr_t target, { ec_cbk_t callback = { .fsetattr = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(FSETATTR) %p", frame); @@ -625,8 +574,7 @@ void ec_fsetattr(call_frame_t * frame, xlator_t * this, uintptr_t target, EC_FLAG_UPDATE_FD_INODE, target, minimum, ec_wind_fsetattr, ec_manager_setattr, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } @@ -634,11 +582,9 @@ void ec_fsetattr(call_frame_t * frame, xlator_t * this, uintptr_t target, fop->int32 = valid; - if (fd != NULL) - { + if (fd != NULL) { fop->fd = fd_ref(fd); - if (fop->fd == NULL) - { + if (fop->fd == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_FILE_DESC_REF_FAIL, "Failed to reference a " @@ -647,15 +593,12 @@ void ec_fsetattr(call_frame_t * frame, xlator_t * this, uintptr_t target, goto out; } } - if (stbuf != NULL) - { + if (stbuf != NULL) { fop->iatt = *stbuf; } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -668,13 +611,10 @@ void ec_fsetattr(call_frame_t * frame, xlator_t * this, uintptr_t target, error = 0; out: - if (fop != NULL) - { + if (fop != NULL) { ec_manager(fop, error); - } - else - { - func(frame, NULL, this, -1, EIO, NULL, NULL, NULL); + } else { + func(frame, NULL, this, -1, error, NULL, NULL, NULL); } } @@ -703,7 +643,7 @@ ec_setxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, { ec_cbk_t callback = { .setxattr = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(SETXATTR) %p", frame); @@ -715,29 +655,24 @@ ec_setxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, EC_FLAG_UPDATE_LOC_INODE, target, minimum, ec_wind_setxattr, ec_manager_xattr, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } fop->int32 = flags; - if (loc != NULL) - { - if (loc_copy(&fop->loc[0], loc) != 0) - { - gf_msg (this->name, GF_LOG_ERROR, 0, + if (loc != NULL) { + if (loc_copy(&fop->loc[0], loc) != 0) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_LOC_COPY_FAIL, "Failed to copy a location."); goto out; } } - if (dict != NULL) - { + if (dict != NULL) { fop->dict = dict_ref(dict); - if (fop->dict == NULL) - { + if (fop->dict == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -746,11 +681,9 @@ ec_setxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -836,7 +769,7 @@ ec_fsetxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, { ec_cbk_t callback = { .fsetxattr = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(FSETXATTR) %p", frame); @@ -848,8 +781,7 @@ ec_fsetxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, EC_FLAG_UPDATE_FD_INODE, target, minimum, ec_wind_fsetxattr, ec_manager_xattr, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } @@ -857,11 +789,9 @@ ec_fsetxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, fop->int32 = flags; - if (fd != NULL) - { + if (fd != NULL) { fop->fd = fd_ref(fd); - if (fop->fd == NULL) - { + if (fop->fd == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_FILE_DESC_REF_FAIL, "Failed to reference a " @@ -870,11 +800,9 @@ ec_fsetxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, goto out; } } - if (dict != NULL) - { + if (dict != NULL) { fop->dict = dict_ref(dict); - if (fop->dict == NULL) - { + if (fop->dict == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -883,11 +811,9 @@ ec_fsetxattr (call_frame_t *frame, xlator_t *this, uintptr_t target, goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -915,20 +841,18 @@ int32_t ec_truncate_write(ec_fop_data_t * fop, uintptr_t mask) struct iobref * iobref = NULL; struct iobuf * iobuf = NULL; struct iovec vector; - int32_t ret = 0; + int32_t err = -ENOMEM; iobref = iobref_new(); - if (iobref == NULL) - { + if (iobref == NULL) { goto out; } iobuf = iobuf_get(fop->xl->ctx->iobuf_pool); - if (iobuf == NULL) - { + if (iobuf == NULL) { goto out; } - if (iobref_add(iobref, iobuf) != 0) - { + err = iobref_add(iobref, iobuf); + if (err != 0) { goto out; } @@ -942,19 +866,17 @@ int32_t ec_truncate_write(ec_fop_data_t * fop, uintptr_t mask) ec_writev(fop->frame, fop->xl, mask, fop->minimum, NULL, NULL, fop->fd, &vector, 1, fop->user_size, 0, iobref, NULL); - ret = 1; + err = 0; out: - if (iobuf != NULL) - { + if (iobuf != NULL) { iobuf_unref(iobuf); } - if (iobref != NULL) - { + if (iobref != NULL) { iobref_unref(iobref); } - return ret; + return err; } int32_t ec_truncate_open_cbk(call_frame_t * frame, void * cookie, @@ -962,12 +884,12 @@ int32_t ec_truncate_open_cbk(call_frame_t * frame, void * cookie, fd_t * fd, dict_t * xdata) { ec_fop_data_t * fop = cookie; + int32_t err; - if (op_ret >= 0) - { - if (!ec_truncate_write(fop->parent, fop->answer->mask)) - { - fop->error = EIO; + if (op_ret >= 0) { + err = ec_truncate_write(fop->parent, fop->answer->mask); + if (err != 0) { + fop->error = -err; } } @@ -976,22 +898,18 @@ int32_t ec_truncate_open_cbk(call_frame_t * frame, void * cookie, int32_t ec_truncate_clean(ec_fop_data_t * fop) { - if (fop->fd == NULL) - { + if (fop->fd == NULL) { fop->fd = fd_create(fop->loc[0].inode, fop->frame->root->pid); - if (fop->fd == NULL) - { - return 0; + if (fop->fd == NULL) { + return -ENOMEM; } ec_open(fop->frame, fop->xl, fop->answer->mask, fop->minimum, ec_truncate_open_cbk, fop, &fop->loc[0], O_RDWR, fop->fd, NULL); - return 1; - } - else - { + return 0; + } else { return ec_truncate_write(fop, fop->answer->mask); } } @@ -1045,47 +963,28 @@ int32_t ec_manager_truncate(ec_fop_data_t * fop, int32_t state) return EC_STATE_PREPARE_ANSWER; case EC_STATE_PREPARE_ANSWER: - cbk = fop->answer; - if (cbk != NULL) - { - if (!ec_dict_combine(cbk, EC_COMBINE_XDATA)) - { - if (cbk->op_ret >= 0) - { - cbk->op_ret = -1; - cbk->op_errno = EIO; - } - } - if (cbk->op_ret < 0) - { - ec_fop_set_error(fop, cbk->op_errno); - } - else - { - ec_iatt_rebuild(fop->xl->private, cbk->iatt, 2, - cbk->count); - - /* This shouldn't fail because we have the inode locked. */ - GF_ASSERT(ec_get_inode_size(fop, - fop->locks[0].lock->loc.inode, - &cbk->iatt[0].ia_size)); - cbk->iatt[1].ia_size = fop->user_size; - /* This shouldn't fail because we have the inode locked. */ - GF_ASSERT(ec_set_inode_size(fop, - fop->locks[0].lock->loc.inode, - fop->user_size)); - if ((cbk->iatt[0].ia_size > cbk->iatt[1].ia_size) && - (fop->user_size != fop->offset)) { - if (!ec_truncate_clean(fop)) { - ec_fop_set_error(fop, EIO); - } + cbk = ec_fop_prepare_answer(fop, _gf_false); + if (cbk != NULL) { + int32_t err; + + ec_iatt_rebuild(fop->xl->private, cbk->iatt, 2, + cbk->count); + + /* This shouldn't fail because we have the inode locked. */ + GF_ASSERT(ec_get_inode_size(fop, fop->locks[0].lock->loc.inode, + &cbk->iatt[0].ia_size)); + cbk->iatt[1].ia_size = fop->user_size; + /* This shouldn't fail because we have the inode locked. */ + GF_ASSERT(ec_set_inode_size(fop, fop->locks[0].lock->loc.inode, + fop->user_size)); + if ((cbk->iatt[0].ia_size > cbk->iatt[1].ia_size) && + (fop->user_size != fop->offset)) { + err = ec_truncate_clean(fop); + if (err != 0) { + ec_cbk_set_error(cbk, -err, _gf_false); } } } - else - { - ec_fop_set_error(fop, EIO); - } return EC_STATE_REPORT; @@ -1156,7 +1055,7 @@ int32_t ec_manager_truncate(ec_fop_data_t * fop, int32_t state) return EC_STATE_END; default: - gf_msg (fop->xl->name, GF_LOG_ERROR, 0, + gf_msg (fop->xl->name, GF_LOG_ERROR, EINVAL, EC_MSG_UNHANDLED_STATE, "Unhandled state %d for %s", state, ec_fop_name(fop->id)); @@ -1171,7 +1070,7 @@ void ec_truncate(call_frame_t * frame, xlator_t * this, uintptr_t target, { ec_cbk_t callback = { .truncate = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(TRUNCATE) %p", frame); @@ -1183,29 +1082,24 @@ void ec_truncate(call_frame_t * frame, xlator_t * this, uintptr_t target, EC_FLAG_UPDATE_LOC_INODE, target, minimum, ec_wind_truncate, ec_manager_truncate, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } fop->offset = offset; - if (loc != NULL) - { - if (loc_copy(&fop->loc[0], loc) != 0) - { - gf_msg (this->name, GF_LOG_ERROR, 0, + if (loc != NULL) { + if (loc_copy(&fop->loc[0], loc) != 0) { + gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_LOC_COPY_FAIL, "Failed to copy a location."); goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -1218,13 +1112,10 @@ void ec_truncate(call_frame_t * frame, xlator_t * this, uintptr_t target, error = 0; out: - if (fop != NULL) - { + if (fop != NULL) { ec_manager(fop, error); - } - else - { - func(frame, NULL, this, -1, EIO, NULL, NULL, NULL); + } else { + func(frame, NULL, this, -1, error, NULL, NULL, NULL); } } @@ -1254,7 +1145,7 @@ void ec_ftruncate(call_frame_t * frame, xlator_t * this, uintptr_t target, { ec_cbk_t callback = { .ftruncate = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(FTRUNCATE) %p", frame); @@ -1266,8 +1157,7 @@ void ec_ftruncate(call_frame_t * frame, xlator_t * this, uintptr_t target, EC_FLAG_UPDATE_FD_INODE, target, minimum, ec_wind_ftruncate, ec_manager_truncate, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } @@ -1275,11 +1165,9 @@ void ec_ftruncate(call_frame_t * frame, xlator_t * this, uintptr_t target, fop->offset = offset; - if (fd != NULL) - { + if (fd != NULL) { fop->fd = fd_ref(fd); - if (fop->fd == NULL) - { + if (fop->fd == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_FILE_DESC_REF_FAIL, "Failed to reference a " @@ -1288,11 +1176,9 @@ void ec_ftruncate(call_frame_t * frame, xlator_t * this, uintptr_t target, goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -1305,13 +1191,10 @@ void ec_ftruncate(call_frame_t * frame, xlator_t * this, uintptr_t target, error = 0; out: - if (fop != NULL) - { + if (fop != NULL) { ec_manager(fop, error); - } - else - { - func(frame, NULL, this, -1, EIO, NULL, NULL, NULL); + } else { + func(frame, NULL, this, -1, error, NULL, NULL, NULL); } } @@ -1401,13 +1284,14 @@ void ec_writev_start(ec_fop_data_t *fop) uint64_t current; uid_t uid; gid_t gid; + int32_t err = -ENOMEM; /* This shouldn't fail because we have the inode locked. */ GF_ASSERT(ec_get_inode_size(fop, fop->fd->inode, ¤t)); fd = fd_anonymous(fop->fd->inode); if (fd == NULL) { - ec_fop_set_error(fop, EIO); + ec_fop_set_error(fop, ENOMEM); return; } @@ -1436,7 +1320,8 @@ void ec_writev_start(ec_fop_data_t *fop) if (iobuf == NULL) { goto out; } - if (iobref_add(iobref, iobuf) != 0) { + err = iobref_add(iobref, iobuf); + if (err != 0) { goto out; } @@ -1486,7 +1371,7 @@ out: fd_unref(fd); - ec_fop_set_error(fop, EIO); + ec_fop_set_error(fop, -err); } int32_t ec_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, @@ -1513,10 +1398,10 @@ void ec_wind_writev(ec_t * ec, ec_fop_data_t * fop, int32_t idx) struct iobref * iobref = NULL; struct iobuf * iobuf = NULL; ssize_t size = 0, bufsize = 0; + int32_t err = -ENOMEM; iobref = iobref_new(); - if (iobref == NULL) - { + if (iobref == NULL) { goto out; } @@ -1524,12 +1409,11 @@ void ec_wind_writev(ec_t * ec, ec_fop_data_t * fop, int32_t idx) bufsize = size / ec->fragments; iobuf = iobuf_get2(fop->xl->ctx->iobuf_pool, bufsize); - if (iobuf == NULL) - { + if (iobuf == NULL) { goto out; } - if (iobref_add(iobref, iobuf) != 0) - { + err = iobref_add(iobref, iobuf); + if (err != 0) { goto out; } @@ -1551,22 +1435,20 @@ void ec_wind_writev(ec_t * ec, ec_fop_data_t * fop, int32_t idx) return; out: - if (iobuf != NULL) - { + if (iobuf != NULL) { iobuf_unref(iobuf); } - if (iobref != NULL) - { + if (iobref != NULL) { iobref_unref(iobref); } - ec_writev_cbk(fop->frame, (void *)(uintptr_t)idx, fop->xl, -1, EIO, NULL, + ec_writev_cbk(fop->frame, (void *)(uintptr_t)idx, fop->xl, -1, -err, NULL, NULL, NULL); } -int32_t ec_manager_writev(ec_fop_data_t * fop, int32_t state) +int32_t ec_manager_writev(ec_fop_data_t *fop, int32_t state) { - ec_cbk_data_t * cbk; + ec_cbk_data_t *cbk; switch (state) { @@ -1590,64 +1472,44 @@ int32_t ec_manager_writev(ec_fop_data_t * fop, int32_t state) return EC_STATE_PREPARE_ANSWER; case EC_STATE_PREPARE_ANSWER: - cbk = fop->answer; - if (cbk != NULL) - { - if (!ec_dict_combine(cbk, EC_COMBINE_XDATA)) - { - if (cbk->op_ret >= 0) - { - cbk->op_ret = -1; - cbk->op_errno = EIO; + cbk = ec_fop_prepare_answer(fop, _gf_false); + if (cbk != NULL) { + ec_t *ec = fop->xl->private; + size_t size; + + ec_iatt_rebuild(fop->xl->private, cbk->iatt, 2, + cbk->count); + + /* This shouldn't fail because we have the inode locked. */ + GF_ASSERT(ec_get_inode_size(fop, fop->fd->inode, + &cbk->iatt[0].ia_size)); + cbk->iatt[1].ia_size = cbk->iatt[0].ia_size; + size = fop->offset + fop->head + fop->user_size; + if (size > cbk->iatt[0].ia_size) { + /* Only update inode size if this is a top level fop. + * Otherwise this is an internal write and the top + * level fop should take care of the real inode size. + */ + if (fop->parent == NULL) { + /* This shouldn't fail because we have the inode + * locked. */ + GF_ASSERT(ec_set_inode_size(fop, fop->fd->inode, + size)); } + cbk->iatt[1].ia_size = size; } - if (cbk->op_ret < 0) - { - ec_fop_set_error(fop, cbk->op_errno); - } - else - { - ec_t * ec = fop->xl->private; - size_t size; - - ec_iatt_rebuild(fop->xl->private, cbk->iatt, 2, - cbk->count); - - /* This shouldn't fail because we have the inode locked. */ - GF_ASSERT(ec_get_inode_size(fop, fop->fd->inode, - &cbk->iatt[0].ia_size)); - cbk->iatt[1].ia_size = cbk->iatt[0].ia_size; - size = fop->offset + fop->head + fop->user_size; - if (size > cbk->iatt[0].ia_size) { - /* Only update inode size if this is a top level fop. - * Otherwise this is an internal write and the top - * level fop should take care of the real inode size. - */ - if (fop->parent == NULL) { - /* This shouldn't fail because we have the inode - * locked. */ - GF_ASSERT(ec_set_inode_size(fop, fop->fd->inode, - size)); - } - cbk->iatt[1].ia_size = size; + if (fop->error == 0) { + cbk->op_ret *= ec->fragments; + if (cbk->op_ret < fop->head) { + cbk->op_ret = 0; + } else { + cbk->op_ret -= fop->head; } - if (fop->error == 0) { - cbk->op_ret *= ec->fragments; - if (cbk->op_ret < fop->head) { - cbk->op_ret = 0; - } else { - cbk->op_ret -= fop->head; - } - if (cbk->op_ret > fop->user_size) { - cbk->op_ret = fop->user_size; - } + if (cbk->op_ret > fop->user_size) { + cbk->op_ret = fop->user_size; } } } - else - { - ec_fop_set_error(fop, EIO); - } return EC_STATE_REPORT; @@ -1694,7 +1556,7 @@ int32_t ec_manager_writev(ec_fop_data_t * fop, int32_t state) return EC_STATE_END; default: - gf_msg (fop->xl->name, GF_LOG_ERROR, 0, + gf_msg (fop->xl->name, GF_LOG_ERROR, EINVAL, EC_MSG_UNHANDLED_STATE, "Unhandled state %d for %s", state, ec_fop_name(fop->id)); @@ -1710,7 +1572,7 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, { ec_cbk_t callback = { .writev = func }; ec_fop_data_t * fop = NULL; - int32_t error = EIO; + int32_t error = ENOMEM; gf_msg_trace ("ec", 0, "EC(WRITE) %p", frame); @@ -1722,8 +1584,7 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, EC_FLAG_UPDATE_FD_INODE, target, minimum, ec_wind_writev, ec_manager_writev, callback, data); - if (fop == NULL) - { + if (fop == NULL) { goto out; } @@ -1733,11 +1594,9 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, fop->use_fd = 1; - if (fd != NULL) - { + if (fd != NULL) { fop->fd = fd_ref(fd); - if (fop->fd == NULL) - { + if (fop->fd == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_FILE_DESC_REF_FAIL, "Failed to reference a " @@ -1746,11 +1605,9 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, goto out; } } - if (count > 0) - { + if (count > 0) { fop->vector = iov_dup(vector, count); - if (fop->vector == NULL) - { + if (fop->vector == NULL) { gf_msg (this->name, GF_LOG_ERROR, ENOMEM, EC_MSG_NO_MEMORY, "Failed to duplicate a " @@ -1760,11 +1617,9 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, } fop->int32 = count; } - if (iobref != NULL) - { + if (iobref != NULL) { fop->buffers = iobref_ref(iobref); - if (fop->buffers == NULL) - { + if (fop->buffers == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_BUF_REF_FAIL, "Failed to reference a " @@ -1773,11 +1628,9 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, goto out; } } - if (xdata != NULL) - { + if (xdata != NULL) { fop->xdata = dict_ref(xdata); - if (fop->xdata == NULL) - { + if (fop->xdata == NULL) { gf_msg (this->name, GF_LOG_ERROR, 0, EC_MSG_DICT_REF_FAIL, "Failed to reference a " @@ -1790,12 +1643,9 @@ void ec_writev(call_frame_t * frame, xlator_t * this, uintptr_t target, error = 0; out: - if (fop != NULL) - { + if (fop != NULL) { ec_manager(fop, error); - } - else - { - func(frame, NULL, this, -1, EIO, NULL, NULL, NULL); + } else { + func(frame, NULL, this, -1, error, NULL, NULL, NULL); } } |