1 Index: src/dird/next_vol.c
2 ===================================================================
3 --- src/dird/next_vol.c (révision 7156)
4 +++ src/dird/next_vol.c (copie de travail)
8 Dmsg0(150, "Call prune_volumes\n");
9 - prune_volumes(jcr, InChanger, mr);
10 + ok = prune_volumes(jcr, InChanger, mr);
12 - ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
13 - if (!ok && create) {
14 - Dmsg4(050, "after prune volumes_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
15 - ok, index, InChanger, mr->VolStatus);
17 - * 5. Try pulling a volume from the Scratch pool
19 - ok = get_scratch_volume(jcr, InChanger, mr);
22 - * If we are using an Autochanger and have not found
23 - * a volume, retry looking for any volume.
28 - continue; /* retry again accepting any volume */
33 + ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
34 + if (!ok && create) {
35 + Dmsg4(050, "after prune volumes_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
36 + ok, index, InChanger, mr->VolStatus);
38 + * 5. Try pulling a volume from the Scratch pool
40 + ok = get_scratch_volume(jcr, InChanger, mr);
41 + Dmsg4(050, "after get scratch volume ok=%d index=%d InChanger=%d Vstat=%s\n",
42 + ok, index, InChanger, mr->VolStatus);
45 + * If we are using an Autochanger and have not found
46 + * a volume, retry looking for any volume.
48 + if (!ok && InChanger) {
50 + continue; /* retry again accepting any volume */
57 Index: src/dird/recycle.c
58 ===================================================================
59 --- src/dird/recycle.c (révision 7156)
60 +++ src/dird/recycle.c (copie de travail)
65 -struct s_oldest_ctx {
67 - char LastWritten[30];
70 -static int oldest_handler(void *ctx, int num_fields, char **row)
72 - struct s_oldest_ctx *oldest = (struct s_oldest_ctx *)ctx;
75 - oldest->MediaId = str_to_int64(row[0]);
76 - bstrncpy(oldest->LastWritten, row[1]?row[1]:"", sizeof(oldest->LastWritten));
77 - Dmsg1(100, "New oldest %s\n", row[1]?row[1]:"");
82 /* Forward referenced functions */
84 bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
91 * Look for oldest Purged volume
93 bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
95 - struct s_oldest_ctx oldest;
97 - POOLMEM *query = get_pool_memory(PM_EMSG);
98 - const char *select =
99 - "SELECT MediaId,LastWritten FROM Media "
100 - "WHERE PoolId=%s AND Recycle=1 AND VolStatus='Purged' "
101 - "AND Enabled=1 AND MediaType='%s' "
102 - "ORDER BY LastWritten ASC,MediaId LIMIT 1";
104 - Dmsg0(100, "Enter recycle_oldest_purged_volume\n");
105 - oldest.MediaId = 0;
106 - Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType);
108 - if (!db_sql_query(jcr->db, query, oldest_handler, (void *)&oldest)) {
109 - Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
110 - Dmsg0(100, "return 0 recycle_oldest_purged_volume query\n");
111 - free_pool_memory(query);
114 - free_pool_memory(query);
115 - Dmsg1(100, "Oldest mediaid=%d\n", oldest.MediaId);
116 - if (oldest.MediaId != 0) {
117 - mr->MediaId = oldest.MediaId;
118 - if (db_get_media_record(jcr, jcr->db, mr)) {
119 - if (recycle_volume(jcr, mr)) {
120 - Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
121 - Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
124 + bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
125 + if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
126 + if (recycle_volume(jcr, mr)) {
127 + Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
128 + Dmsg1(100, "return 1 recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
131 - Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
133 Dmsg0(100, "return 0 recycle_oldest_purged_volume end\n");
135 Index: src/cats/sql_find.c
136 ===================================================================
137 --- src/cats/sql_find.c (révision 7156)
138 +++ src/cats/sql_find.c (copie de travail)
139 @@ -338,17 +338,15 @@
140 edit_int64(mr->PoolId, ed1), mr->MediaType);
144 + POOL_MEM changer(PM_FNAME);
145 /* Find next available volume */
147 - bsnprintf(changer, sizeof(changer), "AND InChanger=1 AND StorageId=%s",
148 - edit_int64(mr->StorageId, ed1));
151 + Mmsg(changer, "AND InChanger=1 AND StorageId=%s",
152 + edit_int64(mr->StorageId, ed1));
154 if (strcmp(mr->VolStatus, "Recycle") == 0 ||
155 strcmp(mr->VolStatus, "Purged") == 0) {
156 - order = "ORDER BY LastWritten ASC,MediaId"; /* take oldest */
157 + order = "AND Recycle=1 ORDER BY LastWritten ASC,MediaId"; /* take oldest that can be recycled */
159 order = "ORDER BY LastWritten IS NULL,LastWritten DESC,MediaId"; /* take most recently written */
164 edit_int64(mr->PoolId, ed1), mr->MediaType,
165 - mr->VolStatus, changer, order, item);
166 + mr->VolStatus, changer.c_str(), order, item);
168 Dmsg1(050, "fnextvol=%s\n", mdb->cmd);
169 if (!QUERY_DB(jcr, mdb, mdb->cmd)) {