Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-ntfs-3g: Commit

external/ntfs-3g


Commit MetaInfo

Revisionb9ad82ced79163d28571a0be65196c078bd67ae6 (tree)
Time2019-01-24 01:43:47
AuthorJean-Pierre André <jean-pierre.andre@wana...>
CommiterJean-Pierre André

Log Message

Truncated SSD trimming zones to granularity supported by the device

When the trimming granularity is greater than the cluster size, the
free zones have to be truncated to match the granularity.

Change Summary

Incremental Difference

--- a/libntfs-3g/ioctl.c
+++ b/libntfs-3g/ioctl.c
@@ -3,7 +3,7 @@
33 *
44 * This module is part of ntfs-3g library
55 *
6- * Copyright (c) 2014-2015 Jean-Pierre Andre
6+ * Copyright (c) 2014-2019 Jean-Pierre Andre
77 * Copyright (c) 2014 Red Hat, Inc.
88 *
99 * This program/include file is free software; you can redistribute it and/or
@@ -225,6 +225,24 @@ not_found:
225225 return 0;
226226 }
227227
228+static inline LCN align_up(ntfs_volume *vol, LCN lcn, u64 granularity)
229+{
230+ u64 aligned;
231+
232+ aligned = (lcn << vol->cluster_size_bits) + granularity - 1;
233+ aligned -= aligned % granularity;
234+ return (aligned >> vol->cluster_size_bits);
235+}
236+
237+static inline u64 align_down(ntfs_volume *vol, u64 count, u64 granularity)
238+{
239+ u64 aligned;
240+
241+ aligned = count << vol->cluster_size_bits;
242+ aligned -= aligned % granularity;
243+ return (aligned >> vol->cluster_size_bits);
244+}
245+
228246 #define FSTRIM_BUFSIZ 4096
229247
230248 /* Trim the filesystem.
@@ -255,11 +273,11 @@ static int fstrim(ntfs_volume *vol, void *data, u64 *trimmed)
255273 * XXX We could fix these limitations in future.
256274 */
257275 if (start != 0 || len != (uint64_t)-1) {
258- ntfs_log_debug("fstrim: setting start or length is not supported\n");
276+ ntfs_log_error("fstrim: setting start or length is not supported\n");
259277 return -EINVAL;
260278 }
261279 if (minlen > vol->cluster_size) {
262- ntfs_log_debug("fstrim: minlen > cluster size is not supported\n");
280+ ntfs_log_error("fstrim: minlen > cluster size is not supported\n");
263281 return -EINVAL;
264282 }
265283
@@ -269,7 +287,7 @@ static int fstrim(ntfs_volume *vol, void *data, u64 *trimmed)
269287 * different.
270288 */
271289 if (!NDevBlock(vol->dev)) {
272- ntfs_log_debug("fstrim: not supported for non-block-device\n");
290+ ntfs_log_error("fstrim: not supported for non-block-device\n");
273291 return -EOPNOTSUPP;
274292 }
275293
@@ -278,15 +296,12 @@ static int fstrim(ntfs_volume *vol, void *data, u64 *trimmed)
278296 if (ret)
279297 return ret;
280298 if (discard_alignment != 0) {
281- ntfs_log_debug("fstrim: backing device is not aligned for discards\n");
282- return -EOPNOTSUPP;
283- }
284- if (discard_granularity > vol->cluster_size) {
285- ntfs_log_debug("fstrim: discard granularity of backing device is larger than cluster size\n");
299+ ntfs_log_error("fstrim: backing device is not aligned for discards\n");
286300 return -EOPNOTSUPP;
287301 }
302+
288303 if (discard_max_bytes == 0) {
289- ntfs_log_debug("fstrim: backing device does not support discard (discard_max_bytes == 0)\n");
304+ ntfs_log_error("fstrim: backing device does not support discard (discard_max_bytes == 0)\n");
290305 return -EOPNOTSUPP;
291306 }
292307
@@ -323,11 +338,14 @@ static int fstrim(ntfs_volume *vol, void *data, u64 *trimmed)
323338 }
324339
325340 /* Trim the clusters in large as possible blocks, but
326- * not larger than discard_max_bytes.
341+ * not larger than discard_max_bytes, and compatible
342+ * with the supported trim granularity.
327343 */
328344 for (start_lcn = start_buf; start_lcn < end_buf; ++start_lcn) {
329345 if (!ntfs_bit_get(buf, start_lcn-start_buf)) {
330346 LCN end_lcn;
347+ LCN aligned_lcn;
348+ u64 aligned_count;
331349
332350 /* Cluster 'start_lcn' is not in use,
333351 * find end of this run.
@@ -338,14 +356,25 @@ static int fstrim(ntfs_volume *vol, void *data, u64 *trimmed)
338356 < discard_max_bytes &&
339357 !ntfs_bit_get(buf, end_lcn-start_buf))
340358 end_lcn++;
341-
342- ret = fstrim_clusters(vol,
343- start_lcn, end_lcn-start_lcn);
344- if (ret)
345- goto free_out;
346-
347- *trimmed += (end_lcn - start_lcn)
359+ aligned_lcn = align_up(vol, start_lcn,
360+ discard_granularity);
361+ if (aligned_lcn >= end_lcn)
362+ aligned_count = 0;
363+ else {
364+ aligned_count =
365+ align_down(vol,
366+ end_lcn - aligned_lcn,
367+ discard_granularity);
368+ }
369+ if (aligned_count) {
370+ ret = fstrim_clusters(vol,
371+ aligned_lcn, aligned_count);
372+ if (ret)
373+ goto free_out;
374+
375+ *trimmed += aligned_count
348376 << vol->cluster_size_bits;
377+ }
349378 start_lcn = end_lcn-1;
350379 }
351380 }
Show on old repository browser