iomap: simplify iomap_iter_advance()
Subsystems (3)
PATCH 1/1 iomap: simplify iomap_iter_advance()
Most callers of iomap_iter_advance() do not need the remaining length returned. Get rid of the extra iomap_length() call that iomap_iter_advance() does. If the caller wants the remaining length, they can make the call to iomap_length().
--- fs/dax.c | 28 ++++++++++++---------------- fs/iomap/buffered-io.c | 16 +++++++++------- fs/iomap/direct-io.c | 6 +++--- fs/iomap/iter.c | 14 +++++--------- fs/iomap/seek.c | 8 ++++---- include/linux/iomap.h | 6 ++---- 6 files changed, 35 insertions(+), 43 deletions(-)
fs/dax.c +12 -16
@@ -1534,7 +1534,7 @@ static int dax_zero_iter(struct iomap_iter *iter, bool *did_zero)/* already zeroed? we're done. */ if (srcmap->type ==IOMAP_HOLE || srcmap->type ==IOMAP_UNWRITTEN ) -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);/* * invalidate the pages whose sharing state is to be changed
@@ -1563,9 +1563,10 @@ static int dax_zero_iter(struct iomap_iter *iter, bool *did_zero)if (ret <0 )return ret; - ret =iomap_iter_advance (iter, &length); + ret =iomap_iter_advance (iter, length);if (ret)return ret; + length =iomap_length (iter); }while (length >0 );if (did_zero)
@@ -1624,7 +1625,7 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter)if (iomap->type ==IOMAP_HOLE || iomap->type ==IOMAP_UNWRITTEN ) { done =iov_iter_zero (min (length, end - pos), iter); -return iomap_iter_advance (iomi, &done); +return iomap_iter_advance (iomi, done); } }
@@ -1709,11 +1710,12 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter) map_len, iter); length = xfer; - ret =iomap_iter_advance (iomi, &length); + ret =iomap_iter_advance (iomi, length);if (!ret && xfer ==0 ) ret = -EFAULT ;if (xfer < map_len)break ; + length =iomap_length (iomi); }dax_read_unlock (id);
@@ -1946,10 +1948,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, unsigned long *pfnp, ret |=VM_FAULT_MAJOR ; } -if (!(ret &VM_FAULT_ERROR )) { -u64 length =PAGE_SIZE ; - iter.status =iomap_iter_advance (&iter, &length); - } +if (!(ret &VM_FAULT_ERROR )) + iter.status =iomap_iter_advance (&iter,PAGE_SIZE ); }if (iomap_errp)
@@ -2061,10 +2061,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp,continue ;/* actually breaks out of the loop */ ret =dax_fault_iter (vmf, &iter, pfnp, &xas, &entry, true); -if (ret !=VM_FAULT_FALLBACK ) { -u64 length =PMD_SIZE ; - iter.status =iomap_iter_advance (&iter, &length); - } +if (ret !=VM_FAULT_FALLBACK ) + iter.status =iomap_iter_advance (&iter,PMD_SIZE ); } unlock_entry:
@@ -2190,7 +2188,6 @@ static int dax_range_compare_iter(struct iomap_iter *it_src,const struct iomap *smap = &it_src->iomap;const struct iomap *dmap = &it_dest->iomap;loff_t pos1 = it_src->pos, pos2 = it_dest->pos; -u64 dest_len;void *saddr, *daddr;int id, ret;
@@ -2223,10 +2220,9 @@ static int dax_range_compare_iter(struct iomap_iter *it_src,dax_read_unlock (id); advance: - dest_len = len; - ret =iomap_iter_advance (it_src, &len); + ret =iomap_iter_advance (it_src, len);if (!ret) - ret =iomap_iter_advance (it_dest, &dest_len); + ret =iomap_iter_advance (it_dest, len);return ret; out_unlock:
fs/iomap/buffered-io.c +9 -7
@@ -373,7 +373,7 @@ static int iomap_readpage_iter(struct iomap_iter *iter, ret =iomap_read_inline_data (iter, folio);if (ret)return ret; -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); }/* zero post-eof blocks as the page may be mapped */
@@ -434,7 +434,7 @@ static int iomap_readpage_iter(struct iomap_iter *iter,* iteration. */ length = pos - iter->pos + plen; -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); } static int iomap_read_folio_iter(struct iomap_iter *iter,
@@ -1036,7 +1036,7 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i, } }else { total_written += written; -iomap_iter_advance (iter, &written); +iomap_iter_advance (iter, written); } }while (iov_iter_count (i) &&iomap_length (iter));
@@ -1305,7 +1305,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter,int status;if (!iomap_want_unshare_iter (iter)) -return iomap_iter_advance (iter, &bytes); +return iomap_iter_advance (iter, bytes); do { struct folio *folio;
@@ -1329,9 +1329,10 @@ static int iomap_unshare_iter(struct iomap_iter *iter,balance_dirty_pages_ratelimited (iter->inode->i_mapping); - status =iomap_iter_advance (iter, &bytes); + status =iomap_iter_advance (iter, bytes);if (status)break ; + bytes =iomap_length (iter); }while (bytes >0 );return status;
@@ -1404,9 +1405,10 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,if (WARN_ON_ONCE (!ret))return -EIO ; - status =iomap_iter_advance (iter, &bytes); + status =iomap_iter_advance (iter, bytes);if (status)break ; + bytes =iomap_length (iter); }while (bytes >0 );if (did_zero)
@@ -1518,7 +1520,7 @@ static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,folio_mark_dirty (folio); } -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); } vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,
fs/iomap/direct-io.c +3 -3
@@ -496,7 +496,7 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)/* Undo iter limitation to current extent */ iov_iter_reexpand (dio->submit.iter, orig_count - copied);if (copied) -return iomap_iter_advance (iter, &copied); +return iomap_iter_advance (iter, copied);return ret; }
@@ -507,7 +507,7 @@ static int iomap_dio_hole_iter(struct iomap_iter *iter, struct iomap_dio *dio) dio->size += length;if (!length)return -EFAULT ; -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); }static int iomap_dio_inline_iter (struct iomap_iter *iomi,struct iomap_dio *dio)
@@ -539,7 +539,7 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio) dio->size += copied;if (!copied)return -EFAULT ; -return iomap_iter_advance (iomi, &copied); +return iomap_iter_advance (iomi, copied); }static int iomap_dio_iter (struct iomap_iter *iter,struct iomap_dio *dio)
fs/iomap/iter.c +5 -9
@@ -13,17 +13,13 @@ static inline void iomap_iter_reset_iomap(struct iomap_iter *iter)memset (&iter->srcmap,0 ,sizeof (iter->srcmap)); } -/* -* Advance the current iterator position and output the length remaining for the -* current mapping. -*/ -int iomap_iter_advance (struct iomap_iter *iter,u64 *count) +/* Advance the current iterator position and decrement the remaining length */ +int iomap_iter_advance (struct iomap_iter *iter,u64 count) { -if (WARN_ON_ONCE (*count >iomap_length (iter))) +if (WARN_ON_ONCE (count >iomap_length (iter)))return -EIO ; - iter->pos += *count; - iter->len -= *count; - *count =iomap_length (iter); + iter->pos += count; + iter->len -= count;return 0 ; }
fs/iomap/seek.c +4 -4
@@ -16,13 +16,13 @@ static int iomap_seek_hole_iter(struct iomap_iter *iter, *hole_pos =mapping_seek_hole_data (iter->inode->i_mapping, iter->pos, iter->pos + length,SEEK_HOLE );if (*hole_pos == iter->pos + length) -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);return 0 ;case IOMAP_HOLE : *hole_pos = iter->pos;return 0 ;default : -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); } }
@@ -59,12 +59,12 @@ static int iomap_seek_data_iter(struct iomap_iter *iter,switch (iter->iomap.type) {case IOMAP_HOLE : -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);case IOMAP_UNWRITTEN : *hole_pos =mapping_seek_hole_data (iter->inode->i_mapping, iter->pos, iter->pos + length,SEEK_DATA );if (*hole_pos <0 ) -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);return 0 ;default : *hole_pos = iter->pos;
include/linux/iomap.h +2 -4
@@ -245,7 +245,7 @@ struct iomap_iter { };int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops); -int iomap_iter_advance (struct iomap_iter *iter,u64 *count); +int iomap_iter_advance (struct iomap_iter *iter,u64 count);/** * iomap_length_trim - trimmed length of the current iomap iteration
@@ -282,9 +282,7 @@ static inline u64 iomap_length(const struct iomap_iter *iter)*/ static inline int iomap_iter_advance_full (struct iomap_iter *iter) { -u64 length =iomap_length (iter); - -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter,iomap_length (iter)); }/**
Signature · 1 line
2.47.3
Quoted 7 lines · Joanne Koong
Most callers of
iomap_iter_advance()do not need the remaining length returned. Get rid of the extraiomap_length()call thatiomap_iter_advance()does. If the caller wants the remaining length, they can make the call toiomap_length().Signed-off-by Joanne Koong <[email protected]>---
Indeed this does clean up some of the calls that create a local var purely to work around the interface. OTOH, the reason I made the advance update the length was so it was clear the remaining length would be used correctly in those looping callers. Otherwise I'm not sure it's clear the bytes/length value needs to be updated and that felt like an easy mistake to make to me.
I don't really have a strong preference so I'll defer to whatever the majority opinion is. I wonder though if something else worth considering is to rename the current helper to __iomap_iter_advance() (or whatever) and make your updated variant of iomap_iter_advance() into a wrapper of it.
Brian
Quoted 296 lines
fs/dax.c | 28 ++++++++++++---------------- fs/iomap/buffered-io.c | 16 +++++++++------- fs/iomap/direct-io.c | 6 +++--- fs/iomap/iter.c | 14 +++++--------- fs/iomap/seek.c | 8 ++++---- include/linux/iomap.h | 6 ++---- 6 files changed, 35 insertions(+), 43 deletions(-)fs/dax.c +12
-16@@ -1534,7 +1534,7 @@ static int dax_zero_iter(struct iomap_iter *iter, bool *did_zero)/* already zeroed? we're done. */ if (srcmap->type ==IOMAP_HOLE || srcmap->type ==IOMAP_UNWRITTEN ) -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);/* * invalidate the pages whose sharing state is to be changed @@ -1563,9 +1563,10 @@ static int dax_zero_iter(struct iomap_iter *iter, bool *did_zero)if (ret <0 )return ret; - ret =iomap_iter_advance (iter, &length); + ret =iomap_iter_advance (iter, length);if (ret)return ret; + length =iomap_length (iter); }while (length >0 );if (did_zero)@@ -1624,7 +1625,7 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter)if (iomap->type ==IOMAP_HOLE || iomap->type ==IOMAP_UNWRITTEN ) { done =iov_iter_zero (min (length, end - pos), iter); -return iomap_iter_advance (iomi, &done); +return iomap_iter_advance (iomi, done); } }@@ -1709,11 +1710,12 @@ static int dax_iomap_iter(struct iomap_iter *iomi, struct iov_iter *iter) map_len, iter); length = xfer; - ret =iomap_iter_advance (iomi, &length); + ret =iomap_iter_advance (iomi, length);if (!ret && xfer ==0 ) ret = -EFAULT ;if (xfer < map_len)break ; + length =iomap_length (iomi); }dax_read_unlock (id);@@ -1946,10 +1948,8 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, unsigned long *pfnp, ret |=VM_FAULT_MAJOR ; } -if (!(ret &VM_FAULT_ERROR )) { -u64 length =PAGE_SIZE ; - iter.status =iomap_iter_advance (&iter, &length); - } +if (!(ret &VM_FAULT_ERROR )) + iter.status =iomap_iter_advance (&iter,PAGE_SIZE ); }if (iomap_errp)@@ -2061,10 +2061,8 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, unsigned long *pfnp,continue ;/* actually breaks out of the loop */ ret =dax_fault_iter (vmf, &iter, pfnp, &xas, &entry, true); -if (ret !=VM_FAULT_FALLBACK ) { -u64 length =PMD_SIZE ; - iter.status =iomap_iter_advance (&iter, &length); - } +if (ret !=VM_FAULT_FALLBACK ) + iter.status =iomap_iter_advance (&iter,PMD_SIZE ); } unlock_entry:@@ -2190,7 +2188,6 @@ static int dax_range_compare_iter(struct iomap_iter *it_src,const struct iomap *smap = &it_src->iomap;const struct iomap *dmap = &it_dest->iomap;loff_t pos1 = it_src->pos, pos2 = it_dest->pos; -u64 dest_len;void *saddr, *daddr;int id, ret;@@ -2223,10 +2220,9 @@ static int dax_range_compare_iter(struct iomap_iter *it_src,dax_read_unlock (id); advance: - dest_len = len; - ret =iomap_iter_advance (it_src, &len); + ret =iomap_iter_advance (it_src, len);if (!ret) - ret =iomap_iter_advance (it_dest, &dest_len); + ret =iomap_iter_advance (it_dest, len);return ret; out_unlock:fs/iomap/buffered-io.c +9
-7@@ -373,7 +373,7 @@ static int iomap_readpage_iter(struct iomap_iter *iter, ret =iomap_read_inline_data (iter, folio);if (ret)return ret; -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); }/* zero post-eof blocks as the page may be mapped */ @@ -434,7 +434,7 @@ static int iomap_readpage_iter(struct iomap_iter *iter,* iteration. */ length = pos - iter->pos + plen; -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); } static int iomap_read_folio_iter(struct iomap_iter *iter,@@ -1036,7 +1036,7 @@ static int iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i, } }else { total_written += written; -iomap_iter_advance (iter, &written); +iomap_iter_advance (iter, written); } }while (iov_iter_count (i) &&iomap_length (iter));@@ -1305,7 +1305,7 @@ static int iomap_unshare_iter(struct iomap_iter *iter,int status;if (!iomap_want_unshare_iter (iter)) -return iomap_iter_advance (iter, &bytes); +return iomap_iter_advance (iter, bytes); do { struct folio *folio;@@ -1329,9 +1329,10 @@ static int iomap_unshare_iter(struct iomap_iter *iter,balance_dirty_pages_ratelimited (iter->inode->i_mapping); - status =iomap_iter_advance (iter, &bytes); + status =iomap_iter_advance (iter, bytes);if (status)break ; + bytes =iomap_length (iter); }while (bytes >0 );return status;@@ -1404,9 +1405,10 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,if (WARN_ON_ONCE (!ret))return -EIO ; - status =iomap_iter_advance (iter, &bytes); + status =iomap_iter_advance (iter, bytes);if (status)break ; + bytes =iomap_length (iter); }while (bytes >0 );if (did_zero)@@ -1518,7 +1520,7 @@ static int iomap_folio_mkwrite_iter(struct iomap_iter *iter,folio_mark_dirty (folio); } -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); } vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops,fs/iomap/direct-io.c +3
-3@@ -496,7 +496,7 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)/* Undo iter limitation to current extent */ iov_iter_reexpand (dio->submit.iter, orig_count - copied);if (copied) -return iomap_iter_advance (iter, &copied); +return iomap_iter_advance (iter, copied);return ret; }@@ -507,7 +507,7 @@ static int iomap_dio_hole_iter(struct iomap_iter *iter, struct iomap_dio *dio) dio->size += length;if (!length)return -EFAULT ; -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); }static int iomap_dio_inline_iter (struct iomap_iter *iomi,struct iomap_dio *dio)@@ -539,7 +539,7 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio) dio->size += copied;if (!copied)return -EFAULT ; -return iomap_iter_advance (iomi, &copied); +return iomap_iter_advance (iomi, copied); }static int iomap_dio_iter (struct iomap_iter *iter,struct iomap_dio *dio)fs/iomap/iter.c +5
-9@@ -13,17 +13,13 @@ static inline void iomap_iter_reset_iomap(struct iomap_iter *iter)memset (&iter->srcmap,0 ,sizeof (iter->srcmap)); } -/* -* Advance the current iterator position and output the length remaining for the -* current mapping. -*/ -int iomap_iter_advance (struct iomap_iter *iter,u64 *count) +/* Advance the current iterator position and decrement the remaining length */ +int iomap_iter_advance (struct iomap_iter *iter,u64 count) { -if (WARN_ON_ONCE (*count >iomap_length (iter))) +if (WARN_ON_ONCE (count >iomap_length (iter)))return -EIO ; - iter->pos += *count; - iter->len -= *count; - *count =iomap_length (iter); + iter->pos += count; + iter->len -= count;return 0 ; }fs/iomap/seek.c +4
-4@@ -16,13 +16,13 @@ static int iomap_seek_hole_iter(struct iomap_iter *iter, *hole_pos =mapping_seek_hole_data (iter->inode->i_mapping, iter->pos, iter->pos + length,SEEK_HOLE );if (*hole_pos == iter->pos + length) -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);return 0 ;case IOMAP_HOLE : *hole_pos = iter->pos;return 0 ;default : -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length); } }@@ -59,12 +59,12 @@ static int iomap_seek_data_iter(struct iomap_iter *iter,switch (iter->iomap.type) {case IOMAP_HOLE : -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);case IOMAP_UNWRITTEN : *hole_pos =mapping_seek_hole_data (iter->inode->i_mapping, iter->pos, iter->pos + length,SEEK_DATA );if (*hole_pos <0 ) -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter, length);return 0 ;default : *hole_pos = iter->pos;include/linux/iomap.h +2
-4@@ -245,7 +245,7 @@ struct iomap_iter { };int iomap_iter (struct iomap_iter *iter,const struct iomap_ops *ops); -int iomap_iter_advance (struct iomap_iter *iter,u64 *count); +int iomap_iter_advance (struct iomap_iter *iter,u64 count);/** * iomap_length_trim - trimmed length of the current iomap iteration @@ -282,9 +282,7 @@ static inline u64 iomap_length(const struct iomap_iter *iter)*/ static inline int iomap_iter_advance_full (struct iomap_iter *iter) { -u64 length =iomap_length (iter); - -return iomap_iter_advance (iter, &length); +return iomap_iter_advance (iter,iomap_length (iter)); }/** Signature · 1 line
2.47.3
Quoted 17 lines · Brian Foster
Quoted 7 lines · Joanne Koong
Most callers of
iomap_iter_advance()do not need the remaining length returned. Get rid of the extraiomap_length()call thatiomap_iter_advance()does. If the caller wants the remaining length, they can make the call toiomap_length().Signed-off-by Joanne Koong <[email protected]>---
Indeed this does clean up some of the calls that create a local var purely to work around the interface. OTOH, the reason I made the advance update the length was so it was clear the remaining length would be used correctly in those looping callers. Otherwise I'm not sure it's clear the bytes/length value needs to be updated and that felt like an easy mistake to make to me.
Quoted 5 lines
I don't really have a strong preference so I'll defer to whatever the majority opinion is. I wonder though if something else worth considering is to rename the current helper to
__iomap_iter_advance()(or whatever) and make your updated variant ofiomap_iter_advance()into a wrapper of it.
That idea sounds good to me too, though I wonder for the naming of it if iomap_iter_advance() should remain the current helper and __iomap_iter_advance() should be for this more-minimal version of it. From what I've seen elsewhere, it seems like the __ prefix is used for minimum behavior and then the non-__ version of it is for that behavior + extra stuff.
Thanks,
Joanne
Quoted 2 lines
Brian
Quoted 24 lines · Joanne Koong
Quoted 17 lines · Brian Foster
Quoted 7 lines · Joanne Koong
Most callers of
iomap_iter_advance()do not need the remaining length returned. Get rid of the extraiomap_length()call thatiomap_iter_advance()does. If the caller wants the remaining length, they can make the call toiomap_length().Signed-off-by Joanne Koong <[email protected]>---
Indeed this does clean up some of the calls that create a local var purely to work around the interface. OTOH, the reason I made the advance update the length was so it was clear the remaining length would be used correctly in those looping callers. Otherwise I'm not sure it's clear the bytes/length value needs to be updated and that felt like an easy mistake to make to me.
Quoted 5 lines
I don't really have a strong preference so I'll defer to whatever the majority opinion is. I wonder though if something else worth considering is to rename the current helper to
__iomap_iter_advance()(or whatever) and make your updated variant ofiomap_iter_advance()into a wrapper of it.
Quoted 7 lines
That idea sounds good to me too, though I wonder for the naming of it if
iomap_iter_advance()should remain the current helper and__iomap_iter_advance()should be for this more-minimal version of it. From what I've seen elsewhere, it seems like the __ prefix is used for minimum behavior and then the non-__ version of it is for that behavior + extra stuff.
IME the __iomap_iter_advance() would be the most low level and flexible version, whereas the wrappers simplify things. There's also the point that the wrapper seems the more common case, so maybe that makes things cleaner if that one is used more often.
But TBH I'm not sure there is strong precedent. I'm content if we can retain the current variant for the callers that take advantage of it. Another idea is you could rename the current function to iomap_iter_advance_and_update_length_for_loopy_callers() and see what alternative suggestions come up. ;)
Brian
Quoted 6 lines
Thanks,
JoanneQuoted 2 lines
Brian
Quoted 10 lines · Brian Foster
IME the
__iomap_iter_advance()would be the most low level and flexible version, whereas the wrappers simplify things. There's also the point that the wrapper seems the more common case, so maybe that makes things cleaner if that one is used more often.But TBH I'm not sure there is strong precedent. I'm content if we can retain the current variant for the callers that take advantage of it. Another idea is you could rename the current function to
iomap_iter_advance_and_update_length_for_loopy_callers()and see what alternative suggestions come up. ;)
Yeah, __ names are a bit nasty. I prefer to mostly limit them to local helpers, or to things with an obvious inline wrapper for the fast path. So I your latest suggestions actually aims in the right directly, but maybe we can shorten the name a little and do something like:
iomap_iter_advance_and_update_len
although even that would probably lead a few lines to spill. iomap_iter_advance_len would be a shorter, but a little more confusing, but still better than __-naming, so maybe it should be fine with a good kerneldoc comment?
Quoted 18 lines · Christoph Hellwig
Quoted 10 lines · Brian Foster
IME the
__iomap_iter_advance()would be the most low level and flexible version, whereas the wrappers simplify things. There's also the point that the wrapper seems the more common case, so maybe that makes things cleaner if that one is used more often.But TBH I'm not sure there is strong precedent. I'm content if we can retain the current variant for the callers that take advantage of it. Another idea is you could rename the current function to
iomap_iter_advance_and_update_length_for_loopy_callers()and see what alternative suggestions come up. ;)Yeah, __ names are a bit nasty. I prefer to mostly limit them to local helpers, or to things with an obvious inline wrapper for the fast path. So I your latest suggestions actually aims in the right directly, but maybe we can shorten the name a little and do something like:
Quoted 7 lines
iomap_iter_advance_and_update_lenalthough even that would probably lead a few lines to spill.
iomap_iter_advance_lenwould be a shorter, but a little more confusing, but still better than __-naming, so maybe it should be fine with a good kerneldoc comment?
Ack, anything like that is fine with me, even something like iomap_iter_advance_and_length() with a comment that just points out it also calls iomap_length().
Another thought was to have one helper that returns the remaining length or error and then a wrapper that translates the return (i.e. return ret
Quoted 1 line
= 0 ? 0 : ret). But when I thought more about it seemed like it just
created confusion.
Brian
Quoted 32 lines · Brian Foster
Quoted 18 lines · Christoph Hellwig
Quoted 10 lines · Brian Foster
IME the
__iomap_iter_advance()would be the most low level and flexible version, whereas the wrappers simplify things. There's also the point that the wrapper seems the more common case, so maybe that makes things cleaner if that one is used more often.But TBH I'm not sure there is strong precedent. I'm content if we can retain the current variant for the callers that take advantage of it. Another idea is you could rename the current function to
iomap_iter_advance_and_update_length_for_loopy_callers()and see what alternative suggestions come up. ;)Yeah, __ names are a bit nasty. I prefer to mostly limit them to local helpers, or to things with an obvious inline wrapper for the fast path. So I your latest suggestions actually aims in the right directly, but maybe we can shorten the name a little and do something like:
Quoted 7 lines
iomap_iter_advance_and_update_lenalthough even that would probably lead a few lines to spill.
iomap_iter_advance_lenwould be a shorter, but a little more confusing, but still better than __-naming, so maybe it should be fine with a good kerneldoc comment?Ack, anything like that is fine with me, even something like
iomap_iter_advance_and_length()with a comment that just points out it also callsiomap_length().
Quoted 7 lines
Another thought was to have one helper that returns the remaining length or error and then a wrapper that translates the return (i.e. return ret
Quoted 1 line
= 0 ? 0 : ret). But when I thought more about it seemed like it just
created confusion.
Brian
I'm looking at this patch again and wondering if the second helper is all that necessary. I feel like if we're adding it because the caller could be confused/unclear about needing to update their local length variable, then wouldn't they also be confused about having to use iomap_iter_advance_and_length() instead of iomap_iter_advance()? I feel like if they know enough to know that they need to use iomap_iter_advance_and_length() instead of iomap_iter_advance(), then they know enough to update their local length variable themsevles through iomap_length(). imo it seems cleaner / less cluttery to just have iomap_iter_advance(). But I'm happy to add the "iomap_advance_and_length()" helper for v2 if you guys disagree and prefer having a 2nd helper.
Thanks,
Joanne
Brian Foster
Reviewed-byQuoted 41 lines · Joanne Koong
Quoted 32 lines · Brian Foster
Quoted 18 lines · Christoph Hellwig
Quoted 10 lines · Brian Foster
IME the
__iomap_iter_advance()would be the most low level and flexible version, whereas the wrappers simplify things. There's also the point that the wrapper seems the more common case, so maybe that makes things cleaner if that one is used more often.But TBH I'm not sure there is strong precedent. I'm content if we can retain the current variant for the callers that take advantage of it. Another idea is you could rename the current function to
iomap_iter_advance_and_update_length_for_loopy_callers()and see what alternative suggestions come up. ;)Yeah, __ names are a bit nasty. I prefer to mostly limit them to local helpers, or to things with an obvious inline wrapper for the fast path. So I your latest suggestions actually aims in the right directly, but maybe we can shorten the name a little and do something like:
Quoted 7 lines
iomap_iter_advance_and_update_lenalthough even that would probably lead a few lines to spill.
iomap_iter_advance_lenwould be a shorter, but a little more confusing, but still better than __-naming, so maybe it should be fine with a good kerneldoc comment?Ack, anything like that is fine with me, even something like
iomap_iter_advance_and_length()with a comment that just points out it also callsiomap_length().Quoted 7 lines
Another thought was to have one helper that returns the remaining length or error and then a wrapper that translates the return (i.e. return ret
Quoted 1 line
= 0 ? 0 : ret). But when I thought more about it seemed like it just
created confusion.
Brian
Quoted 13 lines
I'm looking at this patch again and wondering if the second helper is all that necessary. I feel like if we're adding it because the caller could be confused/unclear about needing to update their local length variable, then wouldn't they also be confused about having to use
iomap_iter_advance_and_length()instead ofiomap_iter_advance()? I feel like if they know enough to know that they need to useiomap_iter_advance_and_length()instead ofiomap_iter_advance(), then they know enough to update their local length variable themsevles throughiomap_length(). imo it seems cleaner / less cluttery to just haveiomap_iter_advance(). But I'm happy to add the "iomap_advance_and_length()" helper for v2 if you guys disagree and prefer having a 2nd helper.
Eh fair point. As mentioned at the top I'm not that worried about it, just wanted to entertain discussion on a potentially clean way to do both (thanks). Sounds more like it's not worth it.
Looking back at the patch again, my only followup comment is for the handful of cases where the newly added iomap_length() is clearly the tail of a loop, could we instead add the call to the loop iteration line? I.e.:
do {
...
iomap_iter_advance();
while ((length = iomap_length(iter)) > 0)With that tweak I'm good with it:
Brian
Quoted 4 lines
Thanks,
Joanne
Quoted 66 lines · Brian Foster
Quoted 41 lines · Joanne Koong
Quoted 32 lines · Brian Foster
Quoted 18 lines · Christoph Hellwig
Quoted 10 lines · Brian Foster
IME the
__iomap_iter_advance()would be the most low level and flexible version, whereas the wrappers simplify things. There's also the point that the wrapper seems the more common case, so maybe that makes things cleaner if that one is used more often.But TBH I'm not sure there is strong precedent. I'm content if we can retain the current variant for the callers that take advantage of it. Another idea is you could rename the current function to
iomap_iter_advance_and_update_length_for_loopy_callers()and see what alternative suggestions come up. ;)Yeah, __ names are a bit nasty. I prefer to mostly limit them to local helpers, or to things with an obvious inline wrapper for the fast path. So I your latest suggestions actually aims in the right directly, but maybe we can shorten the name a little and do something like:
Quoted 7 lines
iomap_iter_advance_and_update_lenalthough even that would probably lead a few lines to spill.
iomap_iter_advance_lenwould be a shorter, but a little more confusing, but still better than __-naming, so maybe it should be fine with a good kerneldoc comment?Ack, anything like that is fine with me, even something like
iomap_iter_advance_and_length()with a comment that just points out it also callsiomap_length().Quoted 7 lines
Another thought was to have one helper that returns the remaining length or error and then a wrapper that translates the return (i.e. return ret
Quoted 1 line
= 0 ? 0 : ret). But when I thought more about it seemed like it just
created confusion.
Brian
Quoted 13 lines
I'm looking at this patch again and wondering if the second helper is all that necessary. I feel like if we're adding it because the caller could be confused/unclear about needing to update their local length variable, then wouldn't they also be confused about having to use
iomap_iter_advance_and_length()instead ofiomap_iter_advance()? I feel like if they know enough to know that they need to useiomap_iter_advance_and_length()instead ofiomap_iter_advance(), then they know enough to update their local length variable themsevles throughiomap_length(). imo it seems cleaner / less cluttery to just haveiomap_iter_advance(). But I'm happy to add the "iomap_advance_and_length()" helper for v2 if you guys disagree and prefer having a 2nd helper.Eh fair point. As mentioned at the top I'm not that worried about it, just wanted to entertain discussion on a potentially clean way to do both (thanks). Sounds more like it's not worth it.
Looking back at the patch again, my only followup comment is for the handful of cases where the newly added
iomap_length()is clearly the tail of a loop, could we instead add the call to the loop iteration line? I.e.:
Quoted 5 lines
do {
...
iomap_iter_advance();
while ((length = iomap_length(iter)) > 0)This sounds great, I will add this in for v2. Thanks for the review and discussion on this.
Quoted 11 lines
With that tweak I'm good with it:
Reviewed-by Brian Foster <[email protected]>Brian
Quoted 4 lines
Thanks,
Joanne