Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Evergreen:11.2
hdparm
hdparm-trim-limit.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File hdparm-trim-limit.patch of Package hdparm
Index: hdparm-9.27/hdparm.c =================================================================== --- hdparm-9.27.orig/hdparm.c +++ hdparm-9.27/hdparm.c @@ -1154,22 +1154,61 @@ static void do_trim_sector_ranges (int f exit(err); } +static void +extract_id_string (__u16 *idw, int words, char *dst) +{ + char *e; + int i, max = words * 2; + + for (i = 0; i < words; ++i) { + __u16 w = idw[i]; + w = (__u16)(__be16)(w); + dst[i*2 ] = w >> 8; + dst[i*2+1] = w; + } + dst[max] = '\0'; + for (e = dst + max; --e != dst;) { + if (*e && *e != ' ') + break; + *e = '\0'; + } +} + +static int +get_trim_dev_limit (void *id) +{ + __u16 *idw = id; + char model[41]; + + if (idw[105] && idw[105] != 0xffff) + return idw[105]; + extract_id_string(idw + 27, 20, model); + if (0 == strcmp(model, "OCZ VERTEX-LE")) + return 8; + if (0 == strcmp(model, "OCZ-VERTEX")) + return 64; + return 1; /* all other drives, including Intel SSDs */ +} + static int do_trim_from_stdin (int fd, const char *devname, void *id) { __u64 *data, range, nsectors = 0, lba_limit; unsigned int max_kb, data_sects, data_bytes; - unsigned int total_ranges = 0, nranges = 0, max_ranges; + unsigned int total_ranges = 0, nranges = 0, max_ranges, dev_limit; int err = 0; id = get_identify_data(fd, id); lba_limit = id ? get_lba_capacity(id) : (1ULL << 48) - 1; + dev_limit = get_trim_dev_limit(id); err = sysfs_get_attr(fd, "queue/max_sectors_kb", "%u", &max_kb, NULL, 0); if (err || max_kb == 0) data_sects = 128; /* "safe" default for most hardware */ else data_sects = max_kb * 2; + if (data_sects > dev_limit) + data_sects = dev_limit; data_bytes = data_sects * 512; data = mmap(NULL, data_bytes, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); @@ -1178,6 +1217,7 @@ do_trim_from_stdin (int fd, const char * perror("mmap(MAP_ANONYMOUS)"); exit(err); } + memset(data, 0, data_bytes); max_ranges = data_bytes / sizeof(range); do { @@ -1201,6 +1241,7 @@ do_trim_from_stdin (int fd, const char * data[nranges++] = __cpu_to_le64(range); if (nranges == max_ranges) { err = trim_sectors(fd, devname, nranges, data, nsectors); + memset(data, 0, data_bytes); nranges = 0; nsectors = 0; } Index: hdparm-9.27/identify.c =================================================================== --- hdparm-9.27.orig/identify.c +++ hdparm-9.27/identify.c @@ -1101,7 +1101,8 @@ void identify (__u16 *id_supplied) sdma_ok = 0; /* word 62 has been re-purposed for non-sdma mode reporting */ printf("\tDMADIR bit required in PACKET commands\n"); } else { - __u8 w62 = val[62], hi = w62 >> 8, lo = w62; + __u16 w62 = val[62]; + __u8 hi = w62 >> 8, lo = w62; if (!w62 || (lo & 0xf8)) sdma_ok = 0; else if (hi && hi != 1 && hi != 2 && hi != 4) @@ -1210,7 +1211,11 @@ void identify (__u16 *id_supplied) __u16 word69 = val[69] & ~(trimz | trimd); /* TRIM bits require special interpretation */ print_features(word69, word69, feat_word69_str); if (val[169] & 1 && val[169] != 0xffff) { /* supports TRIM ? */ - printf("\t *\tData Set Management TRIM supported\n"); + printf("\t *\tData Set Management TRIM supported"); + if (val[105] && val[105] != 0xffff) + printf(" (limit %u block%s)\n", val[105], val[105] > 1 ? "s" : ""); + else + printf(" (limit unknown)\n"); if (val[69] & trimd) { /* Deterministic TRIM support */ if (val[69] & trimz) print_features(trimz, trimz, feat_word69_str);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor