···298299 ret = ocfs2_extent_map_insert(inode, rec,300 le16_to_cpu(el->l_tree_depth));301- if (ret) {302 mlog_errno(ret);303 goto out_free;304 }···427/*428 * Simple rule: on any return code other than -EAGAIN, anything left429 * in the insert_context will be freed.00000430 */431static int ocfs2_extent_map_try_insert(struct inode *inode,432 struct ocfs2_extent_rec *rec,···453 goto out_unlock;454 }4550456 old_ent = ocfs2_extent_map_lookup(em, le32_to_cpu(rec->e_cpos),457- le32_to_cpu(rec->e_clusters), NULL,458- NULL);459460 BUG_ON(!old_ent);461462- ret = -EEXIST;463- if (old_ent->e_tree_depth < tree_depth)0464 goto out_unlock;0465466 if (old_ent->e_tree_depth == tree_depth) {00000467 if (!memcmp(rec, &old_ent->e_rec,468 sizeof(struct ocfs2_extent_rec)))469 ret = 0;000470471- /* FIXME: Should this be ESRCH/EBADR??? */472 goto out_unlock;473 }474···614 tree_depth, &ctxt);615 } while (ret == -EAGAIN);616617- if (ret < 0)618 mlog_errno(ret);619620 if (ctxt.left_ent)
···298299 ret = ocfs2_extent_map_insert(inode, rec,300 le16_to_cpu(el->l_tree_depth));301+ if (ret && (ret != -EEXIST)) {302 mlog_errno(ret);303 goto out_free;304 }···427/*428 * Simple rule: on any return code other than -EAGAIN, anything left429 * in the insert_context will be freed.430+ *431+ * Simple rule #2: A return code of -EEXIST from this function or432+ * its calls to ocfs2_extent_map_insert_entry() signifies that another433+ * thread beat us to the insert. It is not an actual error, but it434+ * tells the caller we have no more work to do.435 */436static int ocfs2_extent_map_try_insert(struct inode *inode,437 struct ocfs2_extent_rec *rec,···448 goto out_unlock;449 }450451+ /* Since insert_entry failed, the map MUST have old_ent */452 old_ent = ocfs2_extent_map_lookup(em, le32_to_cpu(rec->e_cpos),453+ le32_to_cpu(rec->e_clusters),454+ NULL, NULL);455456 BUG_ON(!old_ent);457458+ if (old_ent->e_tree_depth < tree_depth) {459+ /* Another thread beat us to the lower tree_depth */460+ ret = -EEXIST;461 goto out_unlock;462+ }463464 if (old_ent->e_tree_depth == tree_depth) {465+ /*466+ * Another thread beat us to this tree_depth.467+ * Let's make sure we agree with that thread (the468+ * extent_rec should be identical).469+ */470 if (!memcmp(rec, &old_ent->e_rec,471 sizeof(struct ocfs2_extent_rec)))472 ret = 0;473+ else474+ /* FIXME: Should this be ESRCH/EBADR??? */475+ ret = -EEXIST;4760477 goto out_unlock;478 }479···599 tree_depth, &ctxt);600 } while (ret == -EAGAIN);601602+ if ((ret < 0) && (ret != -EEXIST))603 mlog_errno(ret);604605 if (ctxt.left_ent)