33
33
#include <linux/falloc.h>
34
34
#include <linux/fs.h>
35
35
#include <errno.h>
36
- #include <assert.h>
37
36
#include <err.h>
38
37
#include <fcntl.h>
39
38
#include <stdio.h>
@@ -98,7 +97,6 @@ struct blockif_elem {
98
97
};
99
98
100
99
struct blockif_ctxt {
101
- int magic ;
102
100
int fd ;
103
101
int isblk ;
104
102
int candiscard ;
@@ -151,7 +149,6 @@ blockif_flush_cache(struct blockif_ctxt *bc)
151
149
int err ;
152
150
153
151
err = 0 ;
154
- assert (bc != NULL );
155
152
if (!bc -> wce ) {
156
153
if (fsync (bc -> fd ))
157
154
err = errno ;
@@ -168,8 +165,10 @@ blockif_enqueue(struct blockif_ctxt *bc, struct blockif_req *breq,
168
165
int i ;
169
166
170
167
be = TAILQ_FIRST (& bc -> freeq );
171
- assert (be != NULL );
172
- assert (be -> status == BST_FREE );
168
+ if (be == NULL || be -> status != BST_FREE ) {
169
+ WPRINTF (("%s: failed to get element from freeq\n" , __func__ ));
170
+ return 0 ;
171
+ }
173
172
TAILQ_REMOVE (& bc -> freeq , be , link );
174
173
be -> req = breq ;
175
174
be -> op = op ;
@@ -212,7 +211,6 @@ blockif_dequeue(struct blockif_ctxt *bc, pthread_t t, struct blockif_elem **bep)
212
211
TAILQ_FOREACH (be , & bc -> pendq , link ) {
213
212
if (be -> status == BST_PEND )
214
213
break ;
215
- assert (be -> status == BST_BLOCK );
216
214
}
217
215
if (be == NULL )
218
216
return 0 ;
@@ -721,7 +719,6 @@ blockif_open(const char *optstr, const char *ident)
721
719
bc -> sub_file_start_lba = 0 ;
722
720
}
723
721
724
- bc -> magic = BLOCKIF_SIG ;
725
722
bc -> fd = fd ;
726
723
bc -> isblk = S_ISBLK (sbuf .st_mode );
727
724
bc -> candiscard = candiscard ;
@@ -809,28 +806,24 @@ blockif_request(struct blockif_ctxt *bc, struct blockif_req *breq,
809
806
int
810
807
blockif_read (struct blockif_ctxt * bc , struct blockif_req * breq )
811
808
{
812
- assert (bc -> magic == BLOCKIF_SIG );
813
809
return blockif_request (bc , breq , BOP_READ );
814
810
}
815
811
816
812
int
817
813
blockif_write (struct blockif_ctxt * bc , struct blockif_req * breq )
818
814
{
819
- assert (bc -> magic == BLOCKIF_SIG );
820
815
return blockif_request (bc , breq , BOP_WRITE );
821
816
}
822
817
823
818
int
824
819
blockif_flush (struct blockif_ctxt * bc , struct blockif_req * breq )
825
820
{
826
- assert (bc -> magic == BLOCKIF_SIG );
827
821
return blockif_request (bc , breq , BOP_FLUSH );
828
822
}
829
823
830
824
int
831
825
blockif_discard (struct blockif_ctxt * bc , struct blockif_req * breq )
832
826
{
833
- assert (bc -> magic == BLOCKIF_SIG );
834
827
return blockif_request (bc , breq , BOP_DISCARD );
835
828
}
836
829
@@ -839,8 +832,6 @@ blockif_cancel(struct blockif_ctxt *bc, struct blockif_req *breq)
839
832
{
840
833
struct blockif_elem * be ;
841
834
842
- assert (bc -> magic == BLOCKIF_SIG );
843
-
844
835
pthread_mutex_lock (& bc -> mtx );
845
836
/*
846
837
* Check pending requests.
@@ -917,7 +908,6 @@ blockif_close(struct blockif_ctxt *bc)
917
908
void * jval ;
918
909
int i ;
919
910
920
- assert (bc -> magic == BLOCKIF_SIG );
921
911
sub_file_unlock (bc );
922
912
923
913
/*
@@ -936,7 +926,6 @@ blockif_close(struct blockif_ctxt *bc)
936
926
/*
937
927
* Release resources
938
928
*/
939
- bc -> magic = 0 ;
940
929
close (bc -> fd );
941
930
free (bc );
942
931
@@ -955,8 +944,6 @@ blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h, uint8_t *s)
955
944
uint16_t secpt ; /* sectors per track */
956
945
uint8_t heads ;
957
946
958
- assert (bc -> magic == BLOCKIF_SIG );
959
-
960
947
sectors = bc -> size / bc -> sectsz ;
961
948
962
949
/* Clamp the size to the largest possible with CHS */
@@ -998,78 +985,67 @@ blockif_chs(struct blockif_ctxt *bc, uint16_t *c, uint8_t *h, uint8_t *s)
998
985
off_t
999
986
blockif_size (struct blockif_ctxt * bc )
1000
987
{
1001
- assert (bc -> magic == BLOCKIF_SIG );
1002
988
return bc -> size ;
1003
989
}
1004
990
1005
991
int
1006
992
blockif_sectsz (struct blockif_ctxt * bc )
1007
993
{
1008
- assert (bc -> magic == BLOCKIF_SIG );
1009
994
return bc -> sectsz ;
1010
995
}
1011
996
1012
997
void
1013
998
blockif_psectsz (struct blockif_ctxt * bc , int * size , int * off )
1014
999
{
1015
- assert (bc -> magic == BLOCKIF_SIG );
1016
1000
* size = bc -> psectsz ;
1017
1001
* off = bc -> psectoff ;
1018
1002
}
1019
1003
1020
1004
int
1021
1005
blockif_queuesz (struct blockif_ctxt * bc )
1022
1006
{
1023
- assert (bc -> magic == BLOCKIF_SIG );
1024
1007
return (BLOCKIF_MAXREQ - 1 );
1025
1008
}
1026
1009
1027
1010
int
1028
1011
blockif_is_ro (struct blockif_ctxt * bc )
1029
1012
{
1030
- assert (bc -> magic == BLOCKIF_SIG );
1031
1013
return bc -> rdonly ;
1032
1014
}
1033
1015
1034
1016
int
1035
1017
blockif_candiscard (struct blockif_ctxt * bc )
1036
1018
{
1037
- assert (bc -> magic == BLOCKIF_SIG );
1038
1019
return bc -> candiscard ;
1039
1020
}
1040
1021
1041
1022
int
1042
1023
blockif_max_discard_sectors (struct blockif_ctxt * bc )
1043
1024
{
1044
- assert (bc -> magic == BLOCKIF_SIG );
1045
1025
return bc -> max_discard_sectors ;
1046
1026
}
1047
1027
1048
1028
int
1049
1029
blockif_max_discard_seg (struct blockif_ctxt * bc )
1050
1030
{
1051
- assert (bc -> magic == BLOCKIF_SIG );
1052
1031
return bc -> max_discard_seg ;
1053
1032
}
1054
1033
1055
1034
int
1056
1035
blockif_discard_sector_alignment (struct blockif_ctxt * bc )
1057
1036
{
1058
- assert (bc -> magic == BLOCKIF_SIG );
1059
1037
return bc -> discard_sector_alignment ;
1060
1038
}
1061
1039
1062
1040
uint8_t
1063
1041
blockif_get_wce (struct blockif_ctxt * bc )
1064
1042
{
1065
- assert (bc -> magic == BLOCKIF_SIG );
1066
1043
return bc -> wce ;
1067
1044
}
1068
1045
1069
1046
void
1070
1047
blockif_set_wce (struct blockif_ctxt * bc , uint8_t wce )
1071
1048
{
1072
- assert (bc -> magic == BLOCKIF_SIG );
1073
1049
bc -> wce = wce ;
1074
1050
}
1075
1051
@@ -1079,7 +1055,6 @@ blockif_flush_all(struct blockif_ctxt *bc)
1079
1055
int err ;
1080
1056
1081
1057
err = 0 ;
1082
- assert (bc -> magic == BLOCKIF_SIG );
1083
1058
if (fsync (bc -> fd ))
1084
1059
err = errno ;
1085
1060
return err ;
0 commit comments