Mon Mar 16 00:08:10 2009 UTC ()
fix WARNS=3 issues;
* sprinkle const
* avoid tests < 0 on unsigned types
* test fwrite() returns nmemb not <0


(lukem)
diff -r1.4 -r1.5 src/libexec/lfs_cleanerd/cleaner.h
diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/coalesce.c
diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/lfs_cleanerd.c

cvs diff -r1.4 -r1.5 src/libexec/lfs_cleanerd/cleaner.h (expand / switch to unified diff)

--- src/libexec/lfs_cleanerd/cleaner.h 2006/07/31 16:34:42 1.4
+++ src/libexec/lfs_cleanerd/cleaner.h 2009/03/16 00:08:10 1.5
@@ -39,27 +39,27 @@ struct clfs { @@ -39,27 +39,27 @@ struct clfs {
39 39
40/* 40/*
41 * Fraction of the could-be-clean segments required to be clean. 41 * Fraction of the could-be-clean segments required to be clean.
42 */ 42 */
43#define BUSY_LIM 0.5 43#define BUSY_LIM 0.5
44#define IDLE_LIM 0.9 44#define IDLE_LIM 0.9
45 45
46__BEGIN_DECLS 46__BEGIN_DECLS
47 47
48/* lfs_cleanerd.c */ 48/* lfs_cleanerd.c */
49void pwarn(const char *, ...); 49void pwarn(const char *, ...);
50void calc_cb(struct clfs *, int, struct clfs_seguse *); 50void calc_cb(struct clfs *, int, struct clfs_seguse *);
51int clean_fs(struct clfs *, CLEANERINFO *); 51int clean_fs(struct clfs *, CLEANERINFO *);
52void dlog(char *, ...); 52void dlog(const char *, ...);
53void handle_error(struct clfs **, int); 53void handle_error(struct clfs **, int);
54int init_fs(struct clfs *, char *); 54int init_fs(struct clfs *, char *);
55int invalidate_segment(struct clfs *, int); 55int invalidate_segment(struct clfs *, int);
56void lfs_ientry(IFILE **, struct clfs *, ino_t, struct ubuf **); 56void lfs_ientry(IFILE **, struct clfs *, ino_t, struct ubuf **);
57int load_segment(struct clfs *, int, BLOCK_INFO **, int *); 57int load_segment(struct clfs *, int, BLOCK_INFO **, int *);
58int needs_cleaning(struct clfs *, CLEANERINFO *); 58int needs_cleaning(struct clfs *, CLEANERINFO *);
59int32_t parse_pseg(struct clfs *, daddr_t, BLOCK_INFO **, int *); 59int32_t parse_pseg(struct clfs *, daddr_t, BLOCK_INFO **, int *);
60int reinit_fs(struct clfs *); 60int reinit_fs(struct clfs *);
61void reload_ifile(struct clfs *); 61void reload_ifile(struct clfs *);
62void toss_old_blocks(struct clfs *, BLOCK_INFO **, int *, int *); 62void toss_old_blocks(struct clfs *, BLOCK_INFO **, int *, int *);
63 63
64/* cleansrv.c */ 64/* cleansrv.c */
65void check_control_socket(void); 65void check_control_socket(void);

cvs diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/coalesce.c (expand / switch to unified diff)

--- src/libexec/lfs_cleanerd/coalesce.c 2008/05/16 09:21:59 1.16
+++ src/libexec/lfs_cleanerd/coalesce.c 2009/03/16 00:08:10 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: coalesce.c,v 1.16 2008/05/16 09:21:59 hannken Exp $ */ 1/* $NetBSD: coalesce.c,v 1.17 2009/03/16 00:08:10 lukem Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -77,27 +77,27 @@ enum coalesce_returncodes { @@ -77,27 +77,27 @@ enum coalesce_returncodes {
77 COALESCE_TOOSMALL, 77 COALESCE_TOOSMALL,
78 COALESCE_BADSIZE, 78 COALESCE_BADSIZE,
79 COALESCE_BADBLOCKSIZE, 79 COALESCE_BADBLOCKSIZE,
80 COALESCE_NOMEM, 80 COALESCE_NOMEM,
81 COALESCE_BADBMAPV, 81 COALESCE_BADBMAPV,
82 COALESCE_BADMARKV, 82 COALESCE_BADMARKV,
83 COALESCE_NOTWORTHIT, 83 COALESCE_NOTWORTHIT,
84 COALESCE_NOTHINGLEFT, 84 COALESCE_NOTHINGLEFT,
85 COALESCE_EIO, 85 COALESCE_EIO,
86 86
87 COALESCE_MAXERROR 87 COALESCE_MAXERROR
88}; 88};
89 89
90char *coalesce_return[] = { 90const char *coalesce_return[] = {
91 "Successfully coalesced", 91 "Successfully coalesced",
92 "File not in use or inode not found", 92 "File not in use or inode not found",
93 "Not large enough to coalesce", 93 "Not large enough to coalesce",
94 "Negative size", 94 "Negative size",
95 "Not enough blocks to account for size", 95 "Not enough blocks to account for size",
96 "Malloc failed", 96 "Malloc failed",
97 "LFCNBMAPV failed", 97 "LFCNBMAPV failed",
98 "Not broken enough to fix", 98 "Not broken enough to fix",
99 "Too many blocks not found", 99 "Too many blocks not found",
100 "Too many blocks found in active segments", 100 "Too many blocks found in active segments",
101 "I/O error", 101 "I/O error",
102 102
103 "No such error" 103 "No such error"
@@ -157,31 +157,33 @@ clean_inode(struct clfs *fs, ino_t ino) @@ -157,31 +157,33 @@ clean_inode(struct clfs *fs, ino_t ino)
157 if (dip == NULL) 157 if (dip == NULL)
158 return COALESCE_NOINODE; 158 return COALESCE_NOINODE;
159 159
160 /* Compute file block size, set up for bmapv */ 160 /* Compute file block size, set up for bmapv */
161 onb = nb = lblkno(fs, dip->di_size); 161 onb = nb = lblkno(fs, dip->di_size);
162 162
163 /* XXX for now, don't do any file small enough to have fragments */ 163 /* XXX for now, don't do any file small enough to have fragments */
164 if (nb < NDADDR) { 164 if (nb < NDADDR) {
165 free(dip); 165 free(dip);
166 return COALESCE_TOOSMALL; 166 return COALESCE_TOOSMALL;
167 } 167 }
168 168
169 /* Sanity checks */ 169 /* Sanity checks */
 170#if 0 /* di_size is uint64_t -- this is a noop */
170 if (dip->di_size < 0) { 171 if (dip->di_size < 0) {
171 dlog("ino %d, negative size (%" PRId64 ")", ino, dip->di_size); 172 dlog("ino %d, negative size (%" PRId64 ")", ino, dip->di_size);
172 free(dip); 173 free(dip);
173 return COALESCE_BADSIZE; 174 return COALESCE_BADSIZE;
174 } 175 }
 176#endif
175 if (nb > dip->di_blocks) { 177 if (nb > dip->di_blocks) {
176 dlog("ino %d, computed blocks %d > held blocks %d", ino, nb, 178 dlog("ino %d, computed blocks %d > held blocks %d", ino, nb,
177 dip->di_blocks); 179 dip->di_blocks);
178 free(dip); 180 free(dip);
179 return COALESCE_BADBLOCKSIZE; 181 return COALESCE_BADBLOCKSIZE;
180 } 182 }
181 183
182 bip = (BLOCK_INFO *)malloc(sizeof(BLOCK_INFO) * nb); 184 bip = (BLOCK_INFO *)malloc(sizeof(BLOCK_INFO) * nb);
183 if (bip == NULL) { 185 if (bip == NULL) {
184 syslog(LOG_WARNING, "ino %llu, %d blocks: %m", 186 syslog(LOG_WARNING, "ino %llu, %d blocks: %m",
185 (unsigned long long)ino, nb); 187 (unsigned long long)ino, nb);
186 free(dip); 188 free(dip);
187 return COALESCE_NOMEM; 189 return COALESCE_NOMEM;

cvs diff -r1.16 -r1.17 src/libexec/lfs_cleanerd/lfs_cleanerd.c (expand / switch to unified diff)

--- src/libexec/lfs_cleanerd/lfs_cleanerd.c 2009/03/15 23:56:24 1.16
+++ src/libexec/lfs_cleanerd/lfs_cleanerd.c 2009/03/16 00:08:10 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_cleanerd.c,v 1.16 2009/03/15 23:56:24 lukem Exp $ */ 1/* $NetBSD: lfs_cleanerd.c,v 1.17 2009/03/16 00:08:10 lukem Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -89,27 +89,27 @@ struct cleaner_stats { @@ -89,27 +89,27 @@ struct cleaner_stats {
89 89
90extern u_int32_t cksum(void *, size_t); 90extern u_int32_t cksum(void *, size_t);
91extern u_int32_t lfs_sb_cksum(struct dlfs *); 91extern u_int32_t lfs_sb_cksum(struct dlfs *);
92extern u_int32_t lfs_cksum_part(void *, size_t, u_int32_t); 92extern u_int32_t lfs_cksum_part(void *, size_t, u_int32_t);
93extern int ufs_getlbns(struct lfs *, struct uvnode *, daddr_t, struct indir *, int *); 93extern int ufs_getlbns(struct lfs *, struct uvnode *, daddr_t, struct indir *, int *);
94 94
95/* Compat */ 95/* Compat */
96void pwarn(const char *unused, ...) { /* Does nothing */ }; 96void pwarn(const char *unused, ...) { /* Does nothing */ };
97 97
98/* 98/*
99 * Log a message if debugging is turned on. 99 * Log a message if debugging is turned on.
100 */ 100 */
101void 101void
102dlog(char *fmt, ...) 102dlog(const char *fmt, ...)
103{ 103{
104 va_list ap; 104 va_list ap;
105 105
106 if (debug == 0) 106 if (debug == 0)
107 return; 107 return;
108 108
109 va_start(ap, fmt); 109 va_start(ap, fmt);
110 vsyslog(LOG_DEBUG, fmt, ap); 110 vsyslog(LOG_DEBUG, fmt, ap);
111 va_end(ap); 111 va_end(ap);
112} 112}
113 113
114/* 114/*
115 * Remove the specified filesystem from the list, due to its having 115 * Remove the specified filesystem from the list, due to its having
@@ -589,27 +589,27 @@ log_segment_read(struct clfs *fs, int sn @@ -589,27 +589,27 @@ log_segment_read(struct clfs *fs, int sn
589 * the current directory. We don't need to log the location of 589 * the current directory. We don't need to log the location of
590 * the segment, since that can be inferred from the segments up 590 * the segment, since that can be inferred from the segments up
591 * to this point (ss_nextseg field of the previously written segment). 591 * to this point (ss_nextseg field of the previously written segment).
592 * 592 *
593 * We can use this info later to reconstruct the filesystem at any 593 * We can use this info later to reconstruct the filesystem at any
594 * given point in time for analysis, by replaying the log forward 594 * given point in time for analysis, by replaying the log forward
595 * indexed by the segment serial numbers; but it is not suitable 595 * indexed by the segment serial numbers; but it is not suitable
596 * for everyday use since the copylog will be simply enormous. 596 * for everyday use since the copylog will be simply enormous.
597 */ 597 */
598 cp = fd_ptrget(fs->clfs_devvp, sntod(fs, sn)); 598 cp = fd_ptrget(fs->clfs_devvp, sntod(fs, sn));
599 599
600 fp = fopen(copylog_filename, "ab"); 600 fp = fopen(copylog_filename, "ab");
601 if (fp != NULL) { 601 if (fp != NULL) {
602 if (fwrite(cp, (size_t)fs->lfs_ssize, 1, fp) < 0) { 602 if (fwrite(cp, (size_t)fs->lfs_ssize, 1, fp) != 1) {
603 perror("writing segment to copy log"); 603 perror("writing segment to copy log");
604 } 604 }
605 } 605 }
606 fclose(fp); 606 fclose(fp);
607} 607}
608 608
609/* 609/*
610 * Read a segment to populate the BLOCK_INFO structures. 610 * Read a segment to populate the BLOCK_INFO structures.
611 * Return the number of partial segments read and parsed. 611 * Return the number of partial segments read and parsed.
612 */ 612 */
613int 613int
614load_segment(struct clfs *fs, int sn, BLOCK_INFO **bipp, int *bic) 614load_segment(struct clfs *fs, int sn, BLOCK_INFO **bipp, int *bic)
615{ 615{
@@ -674,27 +674,27 @@ calc_cb(struct clfs *fs, int sn, struct  @@ -674,27 +674,27 @@ calc_cb(struct clfs *fs, int sn, struct
674 */ 674 */
675 if (t->nbytes == 0) { 675 if (t->nbytes == 0) {
676 t->flags &= ~SEGUSE_ERROR; /* Strip error once empty */ 676 t->flags &= ~SEGUSE_ERROR; /* Strip error once empty */
677 t->priority = 0; 677 t->priority = 0;
678 return; 678 return;
679 } 679 }
680 680
681 if (t->flags & SEGUSE_ERROR) { /* No good if not already empty */ 681 if (t->flags & SEGUSE_ERROR) { /* No good if not already empty */
682 /* No benefit */ 682 /* No benefit */
683 t->priority = 0; 683 t->priority = 0;
684 return; 684 return;
685 } 685 }
686 686
687 if (t->nbytes < 0 || t->nbytes > fs->lfs_ssize) { 687 if (t->nbytes > fs->lfs_ssize) {
688 /* Another type of error */ 688 /* Another type of error */
689 syslog(LOG_WARNING, "segment %d: bad seguse count %d", 689 syslog(LOG_WARNING, "segment %d: bad seguse count %d",
690 sn, t->nbytes); 690 sn, t->nbytes);
691 t->flags |= SEGUSE_ERROR; 691 t->flags |= SEGUSE_ERROR;
692 t->priority = 0; 692 t->priority = 0;
693 return; 693 return;
694 } 694 }
695 695
696 /* 696 /*
697 * The non-degenerate case. Use Rosenblum's cost-benefit algorithm. 697 * The non-degenerate case. Use Rosenblum's cost-benefit algorithm.
698 * Calculate the benefit from cleaning this segment (one segment, 698 * Calculate the benefit from cleaning this segment (one segment,
699 * minus fragmentation, dirty blocks and a segment summary block) 699 * minus fragmentation, dirty blocks and a segment summary block)
700 * and weigh that against the cost (bytes read plus bytes written). 700 * and weigh that against the cost (bytes read plus bytes written).
@@ -715,30 +715,30 @@ calc_cb(struct clfs *fs, int sn, struct  @@ -715,30 +715,30 @@ calc_cb(struct clfs *fs, int sn, struct
715 715
716 return; 716 return;
717} 717}
718 718
719/* 719/*
720 * Comparator for BLOCK_INFO structures. Anything not in one of the segments 720 * Comparator for BLOCK_INFO structures. Anything not in one of the segments
721 * we're looking at sorts higher; after that we sort first by inode number 721 * we're looking at sorts higher; after that we sort first by inode number
722 * and then by block number (unsigned, i.e., negative sorts higher) *but* 722 * and then by block number (unsigned, i.e., negative sorts higher) *but*
723 * sort inodes before data blocks. 723 * sort inodes before data blocks.
724 */ 724 */
725static int 725static int
726bi_comparator(const void *va, const void *vb) 726bi_comparator(const void *va, const void *vb)
727{ 727{
728 BLOCK_INFO *a, *b; 728 const BLOCK_INFO *a, *b;
729 729
730 a = (BLOCK_INFO *)va; 730 a = (const BLOCK_INFO *)va;
731 b = (BLOCK_INFO *)vb; 731 b = (const BLOCK_INFO *)vb;
732 732
733 /* Check for out-of-place block */ 733 /* Check for out-of-place block */
734 if (a->bi_segcreate == a->bi_daddr && 734 if (a->bi_segcreate == a->bi_daddr &&
735 b->bi_segcreate != b->bi_daddr) 735 b->bi_segcreate != b->bi_daddr)
736 return -1; 736 return -1;
737 if (a->bi_segcreate != a->bi_daddr && 737 if (a->bi_segcreate != a->bi_daddr &&
738 b->bi_segcreate == b->bi_daddr) 738 b->bi_segcreate == b->bi_daddr)
739 return 1; 739 return 1;
740 if (a->bi_size <= 0 && b->bi_size > 0) 740 if (a->bi_size <= 0 && b->bi_size > 0)
741 return 1; 741 return 1;
742 if (b->bi_size <= 0 && a->bi_size > 0) 742 if (b->bi_size <= 0 && a->bi_size > 0)
743 return -1; 743 return -1;
744 744
@@ -755,30 +755,30 @@ bi_comparator(const void *va, const void @@ -755,30 +755,30 @@ bi_comparator(const void *va, const void
755 return 1; 755 return 1;
756 else 756 else
757 return -1; 757 return -1;
758 758
759 return 0; 759 return 0;
760} 760}
761 761
762/* 762/*
763 * Comparator for sort_segments: cost-benefit equation. 763 * Comparator for sort_segments: cost-benefit equation.
764 */ 764 */
765static int 765static int
766cb_comparator(const void *va, const void *vb) 766cb_comparator(const void *va, const void *vb)
767{ 767{
768 struct clfs_seguse *a, *b; 768 const struct clfs_seguse *a, *b;
769 769
770 a = *(struct clfs_seguse **)va; 770 a = *(const struct clfs_seguse * const *)va;
771 b = *(struct clfs_seguse **)vb; 771 b = *(const struct clfs_seguse * const *)vb;
772 return a->priority > b->priority ? -1 : 1; 772 return a->priority > b->priority ? -1 : 1;
773} 773}
774 774
775void 775void
776toss_old_blocks(struct clfs *fs, BLOCK_INFO **bipp, int *bic, int *sizep) 776toss_old_blocks(struct clfs *fs, BLOCK_INFO **bipp, int *bic, int *sizep)
777{ 777{
778 int i, r; 778 int i, r;
779 BLOCK_INFO *bip = *bipp; 779 BLOCK_INFO *bip = *bipp;
780 struct lfs_fcntl_markv /* { 780 struct lfs_fcntl_markv /* {
781 BLOCK_INFO *blkiov; 781 BLOCK_INFO *blkiov;
782 int blkcnt; 782 int blkcnt;
783 } */ lim; 783 } */ lim;
784 784