* Write data to an offset within an object. If the object is too * small, it is expanded as needed. It is possible to specify an * offset beyond the current end of an object and it will be * expanded as needed. Simple implementations of ObjectStore will * just zero the data between the old end of the object and the * newly provided data. More sophisticated implementations of * O
| 898 | * Note that a 0-length write does not affect the size of the object. |
| 899 | */ |
| 900 | void write(const coll_t& cid, const ghobject_t& oid, uint64_t off, uint64_t len, |
| 901 | const ceph::buffer::list& write_data, uint32_t flags = 0) { |
| 902 | using ceph::encode; |
| 903 | Op* _op = _get_next_op(); |
| 904 | uint64_t alignstart = (0 - off) & ~CEPH_PAGE_MASK; |
| 905 | _op->op = OP_WRITE; |
| 906 | _op->cid = _get_coll_id(cid); |
| 907 | _op->oid = _get_object_id(oid); |
| 908 | _op->off = off; |
| 909 | _op->len = len; |
| 910 | ceph_assert(len == write_data.length()); |
| 911 | data.fadvise_flags = data.fadvise_flags | flags; |
| 912 | data.ops = data.ops + 1; |
| 913 | if (!is_format_aligned()) { |
| 914 | encode(write_data, data_misaligned_bl); |
| 915 | return; |
| 916 | } |
| 917 | if (len >= CEPH_PAGE_SIZE + alignstart) { |
| 918 | uint64_t alignlen = (len - alignstart) & CEPH_PAGE_MASK; |
| 919 | uint64_t suffixstart = alignstart + alignlen; |
| 920 | if (alignstart != 0) { |
| 921 | // Misaligned chunk at start |
| 922 | bufferlist prefix; |
| 923 | prefix.substr_of(write_data, 0, alignstart); |
| 924 | encode_nohead(prefix, data_misaligned_bl); |
| 925 | } |
| 926 | // Aligned chunk in middle |
| 927 | bufferlist aligned; |
| 928 | aligned.substr_of(write_data, alignstart, alignlen); |
| 929 | encode_nohead(aligned, data_aligned_bl); |
| 930 | if (suffixstart != len) { |
| 931 | // Misaligned chunk at end |
| 932 | bufferlist suffix; |
| 933 | suffix.substr_of(write_data, suffixstart, len-suffixstart); |
| 934 | encode_nohead(suffix, data_misaligned_bl); |
| 935 | } |
| 936 | } else { |
| 937 | encode_nohead(write_data, data_misaligned_bl); |
| 938 | } |
| 939 | } |
| 940 | /** |
| 941 | * zero out the indicated byte range within an object. Some |
| 942 | * ObjectStore instances may optimize this to release the |
nothing calls this directly
no test coverage detected