| @@ -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 | |
90 | extern u_int32_t cksum(void *, size_t); | | 90 | extern u_int32_t cksum(void *, size_t); |
91 | extern u_int32_t lfs_sb_cksum(struct dlfs *); | | 91 | extern u_int32_t lfs_sb_cksum(struct dlfs *); |
92 | extern u_int32_t lfs_cksum_part(void *, size_t, u_int32_t); | | 92 | extern u_int32_t lfs_cksum_part(void *, size_t, u_int32_t); |
93 | extern int ufs_getlbns(struct lfs *, struct uvnode *, daddr_t, struct indir *, int *); | | 93 | extern int ufs_getlbns(struct lfs *, struct uvnode *, daddr_t, struct indir *, int *); |
94 | | | 94 | |
95 | /* Compat */ | | 95 | /* Compat */ |
96 | void pwarn(const char *unused, ...) { /* Does nothing */ }; | | 96 | void 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 | */ |
101 | void | | 101 | void |
102 | dlog(char *fmt, ...) | | 102 | dlog(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 | */ |
613 | int | | 613 | int |
614 | load_segment(struct clfs *fs, int sn, BLOCK_INFO **bipp, int *bic) | | 614 | load_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 | */ |
725 | static int | | 725 | static int |
726 | bi_comparator(const void *va, const void *vb) | | 726 | bi_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 | */ |
765 | static int | | 765 | static int |
766 | cb_comparator(const void *va, const void *vb) | | 766 | cb_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 | |
775 | void | | 775 | void |
776 | toss_old_blocks(struct clfs *fs, BLOCK_INFO **bipp, int *bic, int *sizep) | | 776 | toss_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 | |